Scilab Aula 2 Background Comandos for while ifthenelse
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 u = [0; 1; 2; 3] ps: ones(1: 3), zeros(0: 3), u($)
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)
Funções function [var. Retorno 1, . . . , var. Retorno. N] = nome. Da. Funcao(param 1, . . . , param. N) // corpo da função end function
Matrizes B. 31 Considere o seguinte sistema de equações: X 1 + x 2 + x 3 = 1 X 1 + 2 x 2 + 3 x 3 = 3 X 1 – x 2 = -3 Utilize a regra de Cramer para determinar x 1, x 2, x 3. X 1 = -1 X 2 = 2 X 3 = 0
Matrizes -->A = [1 -2 3; -sqrt(3) 1 -sqrt(5); 3 -sqrt(7) 1] --> y = [1; π ; e] A = X = -1. 999 1. - 2. 3. -3. 8998 - 1. 7 1. - 2. 2 -1. 5999 3. - 2. 6 1.
Função Exerc 1: Definir uma função que converte um número complexo da forma cartesiana para a forma polar e usá-la em: l z=4+j*4 l z = -3 + j * 5 Exerc 2: Definir uma função que converte um número complexo da forma polar para forma cartesiana e usá-la em: l z = 4*e-j(3 π /4) l z = 2*ej(π /2)
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 = mod = 45. 5. 6568542 b) ang = - 59. 036243 mod = 5. 8309519
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.
Plot B. 21 a) X 1(t) = Re(2 e(-1+j 2 π)t) Pode-se usar: exp(), real()
Plot B. 21 b) X 2(t) = Im(3 – e(1 -2 jπ)t) Usar: imag()
Plot B. 21 c) X 3(t) = 3 – Im(e(1 -2 πj)t)
Fim lfcpc@cin. ufpe. br
- Slides: 14