dawrehxyz icon

mlab

dawrehxyz | PRO | 11/07/16 09:46:47 AM UTC | 0 ⭐ | 313 👁️ | Never ⏰ | []
text |

610 B

|

None

|

0 👍

/

0 👎

function [ p ] = upp2a( n )
 f = @(x) 1 ./ (1 + 8.*(x - 1/9).^2);
h = 4 / (n-1);
xi = @(i,n) -2 + 4*(i-1)/(n-1);
 x = xi(1,n):h:xi(n,n);
y = f(x)';
 A = vander(x);
c = (A\y);
 p = @(x) polyval(c,x);
 end
          n = 7;
 f = @(x) 1 ./ (1 + 8.*(x - 1/9).^2);
h = 4 / (n-1);
xi = @(i,n) -2 + 4*(i-1)/(n-1);
 x = xi(1,n):h:xi(n,n);
y = f(x)';
 xx = xi(1,n):0.01:xi(n,n);
 mypoly = upp2a(n);
linearpoly = interp1(x,y,xx);
splinepoly = spline(x,y,xx);
 xx = xi(1,n):0.01:xi(n,n);
 figure(1);
plot(xx,mypoly(xx));
figure(2);
plot(xx,linearpoly);
figure(3);
plot(xx,splinepoly);

Comments