SHARE
TWEET

Auto Valor e Vetor

a guest Jun 14th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function autovv()
  2.     n = input('N° ordem da matriz M: '); //numero de elementos do vetor x0
  3.     m = ones(n); //matriz que deseja encontrar o auto valor e o auto vetor
  4.     for(i = 1 : n)
  5.         for(j = 1: n)
  6.             printf("Informe o valor do elemento A(%d,%d)", i, j);
  7.             m(i,j) = input("");
  8.         end
  9.     end
  10.     clc
  11.     x0 = []; //auto vetor  incial Obs.: N° de linhas = n° de colunas da matriz M
  12.     for(i = 1 : n)
  13.         if(i == 2) then
  14.             x0(i,1) = 1;
  15.         else
  16.             x0(i,1) = 0;
  17.         end
  18.     end
  19.     k = 1; //auto valor
  20.     ka = 0; //auto valor anterior
  21.     y = x0; // auto vetor
  22.     ka = 0; // auto valor anterior
  23.     l = 1; // contador de iteração
  24.     epsilon = 10^-6;//tolerância
  25.     while(abs(ka-k) > epsilon) do
  26.         x0 = m * y;
  27.         ka = k;
  28.         k = max(abs(x0));
  29.         printf("Iteração %d\n", l);
  30.         printf("Auto valor: %lf ; Auto vetor: (", k);
  31.         for(i = 1 : n)
  32.             y(i) = (1/k)*x0(i);
  33.             printf("%lf ", y(i));
  34.         end
  35.         printf(")\n");
  36.         l = l + 1;
  37.     end
  38. endfunction
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top