dawrehxyz

mlab

Nov 7th, 2016
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. function [ p ] = upp2a( n )
  2.  
  3. f = @(x) 1 ./ (1 + 8.*(x - 1/9).^2);
  4. h = 4 / (n-1);
  5. xi = @(i,n) -2 + 4*(i-1)/(n-1);
  6.  
  7. x = xi(1,n):h:xi(n,n);
  8. y = f(x)';
  9.  
  10. A = vander(x);
  11. c = (A\y);
  12.  
  13. p = @(x) polyval(c,x);
  14.  
  15. end
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. n = 7;
  27.  
  28. f = @(x) 1 ./ (1 + 8.*(x - 1/9).^2);
  29. h = 4 / (n-1);
  30. xi = @(i,n) -2 + 4*(i-1)/(n-1);
  31.  
  32. x = xi(1,n):h:xi(n,n);
  33. y = f(x)';
  34.  
  35. xx = xi(1,n):0.01:xi(n,n);
  36.  
  37. mypoly = upp2a(n);
  38. linearpoly = interp1(x,y,xx);
  39. splinepoly = spline(x,y,xx);
  40.  
  41. xx = xi(1,n):0.01:xi(n,n);
  42.  
  43. figure(1);
  44. plot(xx,mypoly(xx));
  45. figure(2);
  46. plot(xx,linearpoly);
  47. figure(3);
  48. plot(xx,splinepoly);
Advertisement
Add Comment
Please, Sign In to add comment