Advertisement
Enter121

Untitled

Jun 3rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. xs=[15, 40, 60, 75];
  2. ys=[0.203,0.377,0.473,0.497];
  3.  
  4. function y = lagr(x, xs, ys)
  5. y = 0.0;
  6. for k=1:columns(xs)
  7. t = 1.0;
  8. for j=1:columns(xs)
  9. if(j != k )
  10. t=t*((x-xs(j))/(xs(k)-xs(j)));
  11. end
  12. end
  13. y += t*ys(k);
  14. end
  15. end
  16.  
  17. lagr(20,xs,ys)
  18. lagr(45,xs,ys)
  19. lagr(67,xs,ys)
  20. lagr(85,xs,ys)
  21.  
  22.  
  23. step=5;
  24. min=15;
  25. max=75;
  26. x = [min:step:max];
  27. y=x;
  28. for i=1:columns(x)
  29. y(i)=lagr(x(i),xs,ys);
  30. end
  31. plot(x, y);
  32. input(' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement