Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.53 KB | None | 0 0
  1. function plotSpline(coeff, x, y)
  2. plot(x,y,'or');
  3. hold on;
  4. n=size(coeff,1);
  5. s1 = @(t) coeff(1,1)*(t-x(1)).^3 + coeff(1,2)*(t-x(1)).^2 + coeff(1,3)*(t-x(1)) + coeff(1,4)
  6. x1 = (x(1)-1):0.001:x(2);
  7. plot(x1,s1(x1));
  8. for i=2:n-1
  9.     s = @(t) coeff(i,1)*(t-x(i)).^3 + coeff(i,2)*(t-x(i)).^2 + coeff(i,3)*(t-x(i)) + coeff(i,4)
  10.     %S(i) = s;
  11.     xx=x(i):0.001:x(i+1);
  12.     plot(xx,s(xx));
  13. end
  14.  
  15. sn = @(t) coeff(n,1)*(t-x(n)).^3 + coeff(n,2)*(t-x(n)).^2 + coeff(n,3)*(t-x(n)) + coeff(n,4)
  16. xn = x(n):0.001:(x(n)+2);
  17. plot(xn,sn(xn));
  18.  
  19. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement