Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Métodos numéricos - Resolução lista 1
- #
- # ================== Questão 1 ==================
- # 1) Declare, na linha de comando, 3 variáveis (x,y,z) e
- # realize as operações abaixo entre elas
- x = 1;
- y = 2;
- z = 3;
- a = x + y + z;
- b = x - y * z;
- c = x * y / z;
- d = x + y ^ z;
- e = ( x + y ) / z;
- f = x / ( y + z );
- g = 2 * x + 3 * x * y - 7;
- h = x * y * z;
- i = ( x + y ) ^ 2 + ( x - y ) ^ 2;
- j = x ^ 2 - x ^ 2 * y + x * y ^ 2 - y ^ 2;
- k = x ^ 3 + x ^ 2 + x + 1;
- l = 12 * x + 5 - 8;
- # ================== Questão 2 ==================
- # 2) Apresente as respostas da questão anterior num único vetor-linha.
- vetor = [ a b c d e f g h i j k l ];
- # ================== Questão 3 ==================
- # 3) Dado x = [4, 5, 6, 1, 2, 3], escreva esse vetor e explique a ação
- # dos comandos abaixo:
- x = [ 4, 5, 6, 1, 2, 3 ];
- a = x(0);
- b = x(5);
- c = x(2:5);
- d = x(1:end);
- e = x(1:end-1);
- f = x(6:-2:1);
- g = x( [1 5 2 1 1] );
- h = sum(x);
- i = mean(x);
- j = max(x);
- k = min(x);
- l = norm(x);
- # ================== Questão 4 ==================
- # 4) Considere os vetores A = [1 2 3], B = [3 2 1] e a matriz
- # M = [4 5 6; 6 5 3]. Digite os próximos comandos e verifique se
- # sua execução está correta, explique o efeito
- A = [1 2 3]
- B = [3 2 1]
- M = [4 5 6; 6 5 3]
- a = A + B;
- b = A + M;
- c = A' + B;
- d = M - [A;B];
- e = [A;B'];
- f = [A;B];
- g = M - 3;
- h = A * B;
- i = A' * B; % ou A * B'
- j = A. * B;
- k = A. / B;
- l = inv( [M;A] );
- m = det( [M;A] );
- # ================== Questão 5 ==================
- # 5) Leia uma matriz de 3 x 3 elementos. Calcule a soma dos
- # elementos que estão acima da diagonal principal.
- somatorio = 0;
- for i = 1:3
- for j = 1:3
- printf("Matriz[%d][%d]: ", i, j);
- matriz(i,j) = input("");
- if( i < j )
- somatorio += matriz(i,j);
- end
- end
- end
- printf("\n\n");
- matriz
- printf("Valor da soma: %.1f\n", somatorio );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement