Scilab

14
Scilab Aula 2 – Background

description

Scilab. Aula 2 – Background. Comandos for, while, if-then-else. for variável = vetor_linha //corpo end while condição // corpo end. If condição then //corpo elseif condição //corpo else //corpo end. Vetores e Matrizes. Vetor Linha u = 0:3 = [0 1 2 3 ] Vetor Coluna - PowerPoint PPT Presentation

Transcript of Scilab

Page 1: Scilab

Scilab

Aula 2 – Background

Page 2: Scilab

Comandos for, while, if-then-else

for variável = vetor_linha

//corpo

end

while condição

// corpo

end

If condição then//corpo

elseif condição//corpo

else//corpo

end

Page 3: Scilab

Vetores e Matrizes

Vetor Linha

u = 0:3 = [0 1 2 3 ]

Vetor Coluna

u = [0; 1; 2; 3]

ps: ones(1:3), zeros(0:3)

Page 4: Scilab

Vetores e Matrizes

A = [1 2 3; 4 5 6; 7 8 9 ]

B = ones(3,3)

C = [A B]

D = matrix(C,9,1)

diag(A), det(A), eye(m,m), A`, inv(A)

Page 5: Scilab

Funções

function [varRetorno1, ... , varRetornoN] = nomeDaFuncao(param1, ... , paramN)

// corpo da função

end function

Page 6: Scilab

Matrizes

B.31 Considere o seguinte sistema de equações:

X1 + x2 + x3 = 1

X1 + 2x2 + 3x3 = 3

X1 – x2 = -3

Utilize a regra de Cramer para determinar x1,x2,x3.

X1 = -1 X2 = 2 X3 = 0

Page 7: Scilab

Matrizes

-->A = [1 -2 3; -sqrt(3) 1 -sqrt(5); 3 -sqrt(7) 1]

--> y = [1; π ; e]

A =

1. - 2. 3.

- 1.7 1. - 2.2

3. - 2.6 1.

X = -1.999

-3.8998

-1.5999

Page 8: Scilab

Função

Exerc1: Definir uma função que converte um número complexo da forma cartesiana

para a forma polar e usá-la em: z = 4 + j * 4 z = -3 + j * 5

Exerc2: Definir uma função que converte um número complexo da forma polar para forma cartesiana e usá-la em:

z = 4*e-j(3 π /4)

z = 2*ej(π /2)

Page 9: Scilab

Exercício 1

-->function [mod,ang] = cart_to_polar(re,im)

-->mod = sqrt(re^2 + im^2);

-->ang = atan(im/re) * 180/%pi;

-->endfunction

a) ang = 45. mod = 5.6568542

b) ang = - 59.036243 mod = 5.8309519

Page 10: Scilab

Exercicio 2

-->function [re,im] = polar_to_cart(mod, ang)

-->re = mod*cos(ang*%pi/180);

-->im = mod*sin(ang*%pi/180);

-->endfunction

a) im = - 2.8284271 re = - 2.8284271

b) im = 0 re = 2.

Page 11: Scilab

Plot

B.21

a) X1(t) = Re(2e(-1+j2 π)t)

Pode-se usar: exp(), real()

Page 12: Scilab

Plot

B.21

b) X2(t) = Im(3 – e(1-2jπ)t)

Usar: imag()

Page 13: Scilab

Plot

B.21

c) X3(t) = 3 – Im(e(1-2 πj)t)

Page 14: Scilab

Fim

[email protected]