Advertisement
icatalin

matlab 29.03.2018

Mar 29th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. %ce s-a lucrat inainte
  2. function a=METNAIVA(X,Y)
  3. n=length(X)-1
  4. for i=1:n+1
  5. for j=1:n+1
  6. A(i,j)=X(i)^(j-1)
  7. end
  8. end
  9. for i=1:n+1
  10. Ai=A
  11. Ai(:,i)=Y(:)
  12. a(i)=det(Ai)/det(A)
  13. end
  14. end
  15.  
  16.  
  17.  
  18. function lab3
  19. syms x;
  20. f(x)=exp(2*x);
  21. n=3;
  22. X=linspace(-1,1,n+1)
  23. Y=f(X)
  24. ezplot(f,[-1,1])
  25. hold on
  26. plot(X,Y,'r+');
  27. a=METNAIVA(X,Y)
  28. Pn=0
  29. for i=1:n+1
  30. Pn=Pn+(x^(i-1))*a(i);
  31. end
  32. ezplot(Pn,[-1,1])
  33. Pn=inline(Pn,'x')
  34. Pn(0.1)
  35. end
  36.  
  37. function y=METL(X,Y,x)
  38. n=length(X)-1;
  39. Pn=0;
  40. for k=1:n+1
  41. L=1;
  42. for j=1:n+1
  43. if (j~=k)
  44. L=L*(x-X(j))/(X(k)-X(j));
  45. end
  46. end
  47. Pn=Pn+L*Y(k);
  48. end
  49. y=Pn;
  50. end
  51.  
  52.  
  53. function lab3b
  54. syms z;
  55. f(z)=exp(2*z);
  56. n=3;
  57. X=linspace(-1,1,n+1);
  58. Y=f(X);
  59. x=linspace(-1,1,1000);
  60. for i=1:length(x)
  61. y(i)=METL(X,Y,x(i));
  62. end
  63. plot(X,Y,'r+')
  64. plot(x,y)
  65. end
  66.  
  67. %ce am lucrat eu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement