Advertisement
paulogp

Metodo dos Minimos Quadrados

Aug 7th, 2011
1,336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.78 KB | None | 0 0
  1. function[] = mmq(fi, valor)
  2. % paulogp
  3. % metodo dos minimos quadrados
  4.  
  5.     disp(' ');
  6.     matrix= importdata('mmq_tabela.m', '\t');
  7.  
  8.     p = matrix(:, 1)';
  9.     f = matrix(:, 2)';
  10.  
  11.     syms x;
  12.  
  13.     n = length(p);
  14.     m = length(fi);
  15.  
  16.     c = zeros(m, m);
  17.     b = zeros(m, 1);
  18.  
  19.     for i=1:n
  20.         for j=1:m
  21.             for k=j:m
  22.                 c(k, j) = c(k, j) + subs(fi(k), p(i))*subs(fi(j), p(i));
  23.                 c(j, k) = c(k, j);
  24.             end
  25.  
  26.             b(j) = b(j)+f(i)*subs(fi(j),p(i));
  27.         end
  28.     end
  29.  
  30.     a = b\c;
  31.     aStr = mat2str(a);
  32.     disp(['Resultado = ' aStr]);
  33.     disp(' ');
  34. end
  35.  
  36.  
  37. % ficheiro: mmq_tabela.m
  38. 1.00    1.017452
  39. 1.05    0.971622
  40. 1.10    0.930208
  41. 1.15    0.892646
  42. 1.20    0.858464
  43. 1.25    0.827269
  44. 1.30    0.798724
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement