Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.90 KB | None | 0 0
  1. clc;
  2. h=[0,3,6,9,12,15,18,21,24,27,30,33]; %Altura en km
  3. d=[1.91000000000000,1.21000000000000,0.770000000000000,0.470000000000000,0.310000000000000,0.190000000000000,0.120000000000000,0.0750000000000000,0.0460000000000000,0.0290000000000000,0.0180000000000000,0.0110000000000000]; %Densidad en kg/m3
  4.  
  5. %plot(l,p,figura,tamaño de la figura,tamaño,color de relleno, color, color del borde, color)
  6. plot(h,d,'o','MarkerSize',4,'MarkerFaceColor','r','MarkerEdgeColor','r')
  7. %suma de todas los elementos de un vector
  8. format long
  9. 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)];
  10. B=[sum(d);sum(d.*h);sum(d.*h.^2)];
  11. x=inv(A)*B; %valores a0 a1 y a2
  12. %extraccion de coeficientes del modelo
  13. a_0=x(1);
  14. a_1=x(2);
  15. a_2=x(3);
  16.  
  17. syms ll
  18. %POLINOMIO DE GRADO 2
  19. P_2=a_2*ll^2+a_1*ll+a_0;
  20. vpa(P_2,5)
  21. %grado 3
  22. %suma de todas los elementos de un vector
  23. format long
  24. 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)];
  25. B=[sum(d);sum(d.*h);sum(d.*h.^2);sum(d.*h.^3)];
  26. x=inv(A)*B; %valores a0 a1 y a2
  27. %extraccion de coeficientes del modelo
  28. a_0=x(1);
  29. a_1=x(2);
  30. a_2=x(3);
  31. a_3=x(4);
  32. syms ll
  33. %POLINOMIO DE GRADO 3
  34. P_3=a_3*ll^3+a_2*ll^2+a_1*ll+a_0;
  35. vpa(P_3,5)
  36. %GRAFICANDO
  37. hold on
  38. aa=ezplot(P_2,[0,max(h)]);
  39. set(aa,'Color','g');
  40. a2=ezplot(P_3,[0,max(h)]);
  41. set(a2,'Color','b');
  42. legend('Pts. experimentales', 'P_2(ll)', 'P_3(ll)');
  43. % r^2 POLINOMIO DE SEGUNDO GRADO
  44. sr=vpa(sum((d-subs(P_2,h)).^2),5)
  45. st=vpa(sum((d-mean(d)).^2),5)
  46. r=sqrt((st-sr)/st)
  47. sr=vpa(sum((d-subs(P_3,h)).^2),5)
  48. st=vpa(sum((d-mean(d)).^2),5)
  49. r=sqrt((st-sr)/st)
  50. disp('densidad del aire en la Cdmx:')
  51. disp(vpa(subs(P_3,2.25)))
  52. disp('densidad del aire en el Everest:')
  53. disp(vpa(subs(P_3,1.2)))
  54.  
  55. %el de grado tres numericamente es el mejor
  56. %pero decidimos con respecto a la grafica y a numericamente.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement