- #1
maxiann143
- 1
- 0
Maclaurin Series cos x (MATLAB)... can somebody please find my error
a. Consider the MacLauren series for cos x.
Find TN(x) for N = 2, 4, 6, 8. For each of these, graph cos(x) and TN(x) on the same plot for x (-pi/4,pi/4)
y=cos(x);
T2=zeros(1,length(x));
for i=1:length(x)
T2(i)=sum(bn(i,1:3));
end
plot(x,y,x,T2)
title('T2 vs cos x')
>> x=(-pi/4):(pi/400):(pi/4);
bn=zeros(length(x),10);
for i=1:10
for j=1:length(x)
n=i-1;
bn(j,i)=((-1)^n*x(j)^(2*n))/(factorial(2*n));
end
end
y=cos(x);
T2=zeros(1,length(x));
for i=1:length(x)
T2(i)=sum(bn(j,1:3));
end
plot(x,y,x,T2)
title('T2 vs cos x')
a. Consider the MacLauren series for cos x.
Find TN(x) for N = 2, 4, 6, 8. For each of these, graph cos(x) and TN(x) on the same plot for x (-pi/4,pi/4)
y=cos(x);
T2=zeros(1,length(x));
for i=1:length(x)
T2(i)=sum(bn(i,1:3));
end
plot(x,y,x,T2)
title('T2 vs cos x')
>> x=(-pi/4):(pi/400):(pi/4);
bn=zeros(length(x),10);
for i=1:10
for j=1:length(x)
n=i-1;
bn(j,i)=((-1)^n*x(j)^(2*n))/(factorial(2*n));
end
end
y=cos(x);
T2=zeros(1,length(x));
for i=1:length(x)
T2(i)=sum(bn(j,1:3));
end
plot(x,y,x,T2)
title('T2 vs cos x')