Advertisement
franciscominajas

Untitled

Jul 6th, 2020
1,752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.23 KB | None | 0 0
  1. %*****************AJUSTE POLINOMIAL POR MÍNIMOS CUADRADOS***************
  2. clc
  3. clear all
  4. h=[1,2,3,4,5,6,7,8,9,10,11,12];
  5. d=[1.6,2.08,5.12,4.86,3.52,2.95,2.60,1.97,1.68,1.44,1.53,1.75];
  6.  
  7. %plot(l,p,figura,tamaño de la figura,tamaño,color de relleno, color, color del borde, color)
  8. plot(h,d,'o','MarkerSize',4,'MarkerFaceColor','r','MarkerEdgeColor','r')
  9. %suma de todas los elementos de un vector
  10. format long
  11. A=[length(h), sum(h), sum(h.^2); sum(h), sum(h.^2), sum(h.^3);sum(h.^2), sum(h.^3), sum(h.^4)];
  12. B=[sum(d);sum(d.*h);sum(d.*h.^2)];
  13. x=inv(A)*B; %valores a0 a1 y a2
  14. %extraccion de coeficientes del modelo
  15. a_0=x(1);
  16. a_1=x(2);
  17. a_2=x(3);
  18.  
  19. syms ll
  20. %grado 3
  21. %suma de todas los elementos de un vector
  22. format long
  23. A=[length(h), sum(h), sum(h.^2), sum(h.^3); sum(h), sum(h.^2), sum(h.^3), sum(h.^4);sum(h.^2), sum(h.^3), sum(h.^4), sum(h.^5);sum(h.^3),sum(h.^4), sum(h.^5), sum(h.^6)];
  24. B=[sum(d);sum(d.*h);sum(d.*h.^2);sum(d.*h.^3)];
  25. x=inv(A)*B; %valores a0 a1 y a2
  26. %extraccion de coeficientes del modelo
  27. a_0=x(1);
  28. a_1=x(2);
  29. a_2=x(3);
  30. a_3=x(4);
  31. syms ll
  32. %POLINOMIO DE GRADO 3
  33. P_3=a_3*ll^3+a_2*ll^2+a_1*ll+a_0;
  34.  %GRAFICANDO
  35. hold on
  36. a2=ezplot(P_3,[0,max(h)]);
  37. set(a2,'Color','b');
  38. legend('Pts. experimentales', 'P_3(ll)');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement