Buscar

RESPOSTAS LISTA DE VETORES E MATRIZES

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 3, do total de 6 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 6, do total de 6 páginas

Prévia do material em texto

RESPOSTAS LISTA DE VETORES E MATRIZES 
 
EXERCÍCIO 1) 
soma = 0 
for i = 1:length(v) 
 soma = soma + v(i) 
end 
m = soma/qt 
endfunction 
printf("CALCULO DA MÉDIA \n"); 
n = input("Digite um valor positivo ou um negativo para sair: ");; 
i = 0; 
while n >= 0 
i = i + 1 
vet(i) = n 
n = input("Digite um valor positivo ou um negativo para sair: "); 
end 
printf("Média dos valores digitados: %g", media(vet)); 
 
EXERCÍCIO 2) 
clc; clear; 
printf("CALCULO DA MÉDIA \n"); 
j = 0; k = 0; 
for i = 1:20 
 n = input("Digite um número: "); 
 if modulo(n, 2) == 0 then 
 j = j + 1 
 vetpar(j) = n 
 else 
 k = k + 1 
 vetimpar(k) = n 
 end 
end 
printf("Vetor com os valores pares: \n"); 
printf("%g ", vetpar) 
printf("\nVetor com os valores impares: \n"); 
printf("%g ", vetimpar) 
 
EXERCÍCIO 3) 
clear;clc; 
for i=1:10 
 alt(i) = input("Digite uma altura: "); 
end 
media = sum(alt) / length(alt); 
printf("Altura média: %.2f\n",media); 
printf("Alturas maiores do que a média: "); 
for i=1:length(alt) 
 if alt(i) > media then 
 printf("%.2f ,",alt(i)); 
 end 
end 
 
EXERCÍCIO 4) 
clc; clear; 
n = input("Digite o vetor do número em binário: "); 
soma = 0; 
for i = 1:length(n); 
 soma = soma + (2^(i-1))*n(length(n) - i + 1); 
end 
printf("Correspondente em decimal: %g", soma); 
//A formula e o resultado da lista estão errados!!!!!!!! 
 
EXERCÍCIO 5) 
clc; clear; 
maior = -%inf; 
menor = +%inf; 
k = 0; 
for i = 1:10 
 sexo(i) = input("Digite o sexo (1-masculino ou 2-feminino): "); 
 alt(i) = input("Digite a altura: "); 
 if alt(i) > maior then 
 maior = alt(i); 
 end 
 if alt(i) < menor then 
 menor = alt(i); 
 end 
 if sexo(i)==2 then 
 k = k + 1; 
 altm(k)=alt(i); 
 end 
end 
mediam = sum(altm)/length(altm); 
mediag = sum(alt)/length(alt); 
printf("Maior altura: %.2f \nMenor altura: %.2f \n",maior,menor); 
printf("Alturas das mulheres com mais de %.2f: \n",mediam); 
for i = 1:10 
 if sexo(i) == 2 then 
 if alt(i) > mediam then 
 printf("%.2f ", alt(i)); 
 end 
 end 
end 
printf("\nAlturas das pessoas com menos de %.2f: \n",mediag); 
for i = 1:10 
 if alt(i) < mediag then 
 printf("%.2f ", alt(i)); 
 end 
end 
 
EXERCÍCIO 6) 
clc; clear; 
maior = -%inf; 
menor = +%inf; 
for i = 1:3 
 msg = 'Digite a temperatura do ' + string (i) + 'o dia: '; 
 temp = input(msg); 
 if temp > maior then 
 maior = temp; 
 diamaior = i; 
 end 
 if temp < menor 
 menor = temp; 
 diamenor = i; 
 end 
end 
printf("A maior temperatura foi no %gº dia e a menor temperatura foi no %gº 
dia.",diamaior,diamenor); 
 
EXERCÍCIO 7) 
clc; clear; 
maxi = -%inf; 
mini = %inf; 
for i = 1:10 
 msg = 'Digite o '+string(i)+'° valor: ' 
 v(i) = input(msg); 
 if v(i) > maxi then 
 maxi = v(i); 
 end 
 if v(i) < mini then 
 mini = v(i); 
 end 
end 
for i = 1:10 
 v2(i) = (((v(i) - mini)/(maxi - mini)) * (99)) + 1; 
end 
printf("-------------- \nLidos | Normalizados \n-------------- \n"); 
for i = 1:10 
 printf(" %g | %6.3f \n", v(i), v2(i)) 
end 
 
EXERCÍCIO 8) 
clc; clear; 
cidade1 = [30 24 18 12 22 25 22 19 24 26 29 34]; 
cidade2 = [30 27 20 16 25 25 26 22 24 28 29 38]; 
k=0; 
for i = 1:length(cidade1); 
 if cidade1(i) == cidade2(i) then 
 k=k+1; 
 igual(k) = i; 
 end 
end 
printf("Meses com média de temperatura iguais: "); 
printf("%g, ",igual); 
 
EXERCÍCIO 9) 
clc; clear; 
num = input("Insira a chapa: "); 
i = 0; 
while num ~= 0 
 i = i + 1; 
 v(i) = num; 
 num = input("Insira a chapa: "); 
end 
k=length(v); 
for i= 1:length(v) 
 vet(k) = v(i); 
 k=k-1; 
end 
printf("Ordem de procesamento das chapas: \n"); 
printf("%g, ",vet); 
 
EXERCÍCIO 10) 
clc; clear; 
d = 0; 
k = 0; 
for i = 1:3 
 for j = 1:3 
 m(i, j) = input(sprintf("Digite o valor da posição [%g, %g]: ", i, j)); 
 if i == j then 
 d = d +1; 
 p(d) = m(i, j); 
 end 
 if i+j==4 then 
 k = k +1; 
 s(k)= m(i, j); 
 end 
 end 
end 
printf("Matriz inserida: \n\n"); 
disp(m); 
printf("\nElementos da diagonal primária: "); 
printf("%g ", p); 
printf("\nElementos da diagonal secundária: " ); 
printf("%g ", s); 
 
 
 
EXERCÍCIO 11) 
clc; clear; 
inf = %t; 
sup = %t; 
for i = 1:3 
 for j = 1:3 
 m(i, j) = input(sprintf("Digite o valor da posição [%g, %g]:",i,j)); 
 if j > i & m(i, j) ~= 0 then 
 inf = %f 
 end 
 if j < i & m(i, j) ~= 0 then 
 sup = %f 
 end 
 end 
end 
printf("Matriz inserida: \n"); 
disp(m); 
if inf & sup then 
 printf("\nMatriz diagonal."); 
elseif inf then 
 printf("\nMatriz triangular inferior."); 
elseif sup then 
 printf("\nMatriz triangular superior."); 
else 
 printf("\nMatriz regular."); 
end 
 
EXERCÍCIO 11) 
clc; clear; 
ind = [2300 5000; 3400 1500;1340 1600]; 
pro = [30 15 65]; 
lucro = 0; lucro2 = 0; 
for i = 1:3 
 lucro = lucro + ind(i, 1) * pro(i) 
 lucro2 = lucro2 + ind(i, 2) * pro(i) 
end 
printf("Lucro da industria 1: %g \nLucro da industria 2: %g\n", lucro, lucro2); 
if lucro > lucro2 then 
 u =1 
else 
 u= 2 
end 
printf("\nO invetimento na industra %g é o melhor", u); 
 
EXERCÍCIO 12) 
clc; clear; 
turno = [1.7 1.8 2.0 2.4 2.7 2.5 2.1;2.1 2.4 2.3 2.2 2.5 2.0 1.8;2.4 2.1 2.5 2.3 2.2 2.2 2.0]; 
soma = 0 
for i = 1:size(turno, 1) 
 for j = 1:size(turno, 2) 
 soma = soma + turno(i, j) 
 end 
end 
media = soma/prod(size(turno)); 
printf("Dias em que a produção ficou abaixo da média (%g)\n", media) 
for i = 1:size(turno, 1) 
 printf("Turno %g \n", i) 
 for j = 1:size(turno, 2) 
 if turno(i, j) < media then 
 printf("%g, ", j) 
 end 
 end 
 printf("\n") 
end 
 
EXERCÍCIO 13) 
clc; clear; 
matriz = [2 5 7 3 2;3 5 6 2 6;1 8 9 3 5;3 5 6 2 1;4 9 9 0 4]; 
for i = 1:size(matriz, 1) 
 soma = 0 
 for j = 1:size(matriz, 2) 
 soma = soma + matriz(i, j) 
 end 
 printf("Soma da linha %g: %g \n", i, soma) 
end 
 
EXERCÍCIO 14) 
clc; clear; 
for i = 1:3 
 for j = 1:3 
 m(i, j) = input("Digite um número: "); 
 end 
end 
printf("Matriz de entrada \n"); 
disp(m); 
[nl,nc] = size(m); 
for i = 1:nl 
 for j = 1:nc; 
 m90(j, 4-i) = m(i, j); 
 end 
end 
printf("\nMatriz rotacionada 90° \n"); 
disp(m90);

Continue navegando