Codigo

You might also like

You are on page 1of 1

clf,

clear screen,
syms('x','y','fx','fxm','gh','fnx');
%%%%%%%%%%%%%%%%%%%%% D A T O S D E E N T R A D A
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fx=cos(x);%ESTA ES LA FUNCION EN LA FUNCION A LA CUAL SE LE OBTIENE LA SERIE DE
MACLAWRIN
n=5;%ESTE ES EL N�MERO INICIAL DE TERMINOS DE LA SERIE (MENOS DE 5)
c=6;%PUNTO EN EL CUAL SE EVAL�A EL ERROR)
tolerancia=.001;%TOLERANCIA PERMITIDA PARA EL POLINOMIO (EN EL PUNTO C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%
fnx(1,1)=subs(fx,0);
gh(1,1)=subs(fx,0);
for i=1:n
fnx(i+1,1)=(diff(fx,i))/(factorial(i)), gh(i+1,1)=(subs(fnx(i+1,1),0))*x^i,
end
fxm=sum(gh);
d=abs(subs(fxm,c));
e=abs(subs(fx,c));
error=abs(d-e),
while error > tolerancia
n=n+1
fnx(n,1)=((diff(fx,n))/(factorial(n))),
gh(n,1)=((subs(fnx(n,1),0))*x^n);
fxm=sum(gh), d=abs(subs(fxm,c)),
e=abs(subs(fx,c)),
error=abs(d-e)
end
f1=-(abs(c)+1);f2=abs(c)+1;
f=f1:0.1:f2;f3=subs(fx,x,f);
ezplot(fxm,f); hold on;
plot(f,f3,'m'),
clc
disp(' este es el polinomio de Maclaurin ')
pretty(fxm)
disp('el n�mero de t�rminos requeridos para la serie son'),n
error
legend('serie de Maclaurin','Funci�n original')

You might also like