Taylor series: Error estimation

4 vues (au cours des 30 derniers jours)
Rahul Janardhanan
Rahul Janardhanan le 29 Août 2020
Commenté : David Hill le 30 Août 2020
Trying to estimate the error for taylor series expansion for 1/1-x. I'm trying to see the convergence for various values of N (no. of iterations) within a certain domain (x). I want to know how to calculate the error and plot it vs changing N.
This is what I have so far:
x= -0.9:0.05:0.9;
y= 1./(1-x);
N = 1; %N: no. of terms
y1 = 0*y;
for i = 0:N
y1= y1+(x.^i);
e1= abs(y-y1);
end
N2 = 2;
y2=0*y;
for i = 0:N2
y2 = y2+(x.^i);
e2= abs(y-y2);
end
N3 = 10;
y3=0*y;
for i= 0:N3
y3= y3+(x.^i);
e3= abs(y-y3);
end
N4 = 100;
y4=0*y;
e4 = 0*0;
for i = 0:N4
y4 = y4+(x.^i);
e4 = abs(y-y4);
end
hold on
plot(x,y,'*r')
plot(x,y1,'-b');
plot(x,y2,'^g');
plot(x,y3,'>k');
plot(x,y4,'--m');
hold off
figure
hold on
grid on
plot(1:N+1,e1,'ok'); %Matlab shows an error while doing this
plot(1:N2+1,e2,'-b');
plot(1:N3+1,e3,'^g');
plot(1:N4+1,e4,'pc');
hold off

Réponses (1)

David Hill
David Hill le 30 Août 2020
x= (-0.9:0.05:0.9)';
y= 1./(1-x);
m=cumsum(repmat(x,1,101).^(0:100),2);
err=abs(y-m);
surf(repmat(x,1,101),repmat([0:100],37,1),err);
figure;
hold on;
grid on;
plot(x,y,'*r');
plot(x,m(:,2),'-b');
plot(x,m(:,3),'^g');
plot(x,m(:,11),'>k');
plot(x,m(:,101),'--m');
  2 commentaires
Rahul Janardhanan
Rahul Janardhanan le 30 Août 2020
Can you please elaborate about what the surf plot displays? Thanks!
David Hill
David Hill le 30 Août 2020
The surface plot is displaying all the x-values, N from 0-100, and corresponding errors on the z-axis.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by