Advertisement
maestro252

punto7periodica

Apr 4th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.27 KB | None | 0 0
  1. clear all;
  2. clc;
  3. format long;
  4. windmill = xlsread('windmill.xlsx');
  5. for i = 1:size(windmill,1)
  6.    m(i) = i/12;
  7. end
  8.  
  9.  
  10. cont = size(windmill,1);
  11. b = windmill;
  12.  
  13. for i = 0:59
  14.    for j = 1:4
  15.       if j == 1
  16.          a(i+1,j) = 1;
  17.       end
  18.       if j == 2
  19.          a(i+1,j) = cos(2*pi*i/12);
  20.       end
  21.       if j == 3
  22.          a(i+1,j) = sin(2*pi*i/12);
  23.       end
  24.       if j == 4
  25.          a(i+1,j) = cos(4*pi*i/12);
  26.       end
  27.    end
  28. end
  29.  
  30. at = transpose(a);
  31.  
  32. newa = mtimes(at, a);
  33. newb = mtimes(at, b);
  34.  
  35. n = size(newa, 1);
  36.  
  37. for j = 1 : n - 1
  38.     if abs(newa(j,j)) < eps; error('Pivote cero encontrado'); end;
  39.     for i = j + 1 : n
  40.         mult = newa(i,j)/newa(j,j);
  41.         for k = j + 1 : n
  42.             newa(i,k) = newa(i,k) - mult * newa(j,k);
  43.         end
  44.         newb(i) = newb(i) - mult * newb(j);
  45.     end
  46. end
  47.  
  48. for i = n : -1 : 1
  49.     for j = i + 1 : n
  50.         newb(i) = newb(i) - newa(i,j)*x(j);
  51.     end
  52.     x(i) = newb(i) / newa (i, i);
  53. end
  54.  
  55. x = transpose(x);
  56. ax = mtimes(a, x);
  57. gamma = minus(b, ax);
  58.  
  59. ec = 0;
  60. for i = 1 : size(gamma)
  61.    ec = ec + (gamma(i))^2;
  62. end
  63.  
  64. rmec = sqrt(ec/(cont));
  65.  
  66.  
  67. for i = 1 : cont
  68.    d(i) = x(1) + x(2)*cos(2*pi*i/12) + x(3)*sin(2*pi*i/12) + x(4)*cos(4*pi*i/12);
  69. end
  70.  
  71. plot(m, windmill, '*',m,d);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement