Maclaurin Series cos x (MATLAB) can somebody find my error

In summary: T4(i)=sum(bn(i,1:5));endplot(x,y,x,T4)title('T4 vs cos x')y=cos(x);T6=zeros(1,length(x));for i=1:length(x) T6(i)=sum(bn(i,1:7));endplot(x,y,x,T6)title('T6 vs cos x')y=cos(x);T8=zeros(1,length(x));for i=1:length(x) T8(i)=sum(bn(i,1:9));endplot(x,y,x,T8)title('T8 vs cos x')In summary, The conversation discusses the Maclaurin
  • #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')
 
Physics news on Phys.org
  • #2
y=cos(x);T4=zeros(1,length(x));for i=1:length(x) T4(i)=sum(bn(j,1:5));endplot(x,y,x,T4)title('T4 vs cos x')y=cos(x);T6=zeros(1,length(x));for i=1:length(x) T6(i)=sum(bn(j,1:7));endplot(x,y,x,T6)title('T6 vs cos x')y=cos(x);T8=zeros(1,length(x));for i=1:length(x) T8(i)=sum(bn(j,1:9));endplot(x,y,x,T8)title('T8 vs cos x')Error: Index exceeds matrix dimensions.Solution: The error is caused by the incorrect indexing in the for loops. The variable i should be used instead of j in the for loop where the summation is calculated. The corrected code is shown below.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)); endendy=cos(x);T2=zeros(1,length(x));for i=1:length(x) T2(i)=sum(bn(i,1:3));endplot(x,y,x,T2)title('T2 vs cos x')y=cos(x);T4=zeros(1,length(
 

Related to Maclaurin Series cos x (MATLAB) can somebody find my error

1. What is a Maclaurin Series?

A Maclaurin Series is a special type of power series expansion that represents a function as an infinite sum of terms. It is centered at x=0 and is used to approximate a function by using its derivatives at that point.

2. How do you find the Maclaurin Series for cosine in MATLAB?

To find the Maclaurin Series for cosine in MATLAB, you can use the function "cos(x)" and specify the center of the expansion as 0. This will give you an infinite series of terms with increasing powers of x.

3. What does it mean to find an error in a Maclaurin Series?

Finding an error in a Maclaurin Series means comparing the value of the series at a given point to the actual value of the function at that point. This can help determine the accuracy of the approximation and the number of terms needed for a desired level of precision.

4. Why might there be an error in a Maclaurin Series for cosine in MATLAB?

There may be an error in a Maclaurin Series for cosine in MATLAB due to rounding errors or if the series is truncated after a certain number of terms. Additionally, if the function has a larger interval of convergence, the series may not be accurate for all values within that interval.

5. How can I check for errors in my Maclaurin Series for cosine in MATLAB?

You can check for errors in your Maclaurin Series for cosine in MATLAB by comparing the output of the series to the actual value of cosine at various points. Additionally, you can use built-in functions like "abs()" or "abserr()" to calculate the absolute error and determine the accuracy of the series.

Similar threads

  • Calculus and Beyond Homework Help
Replies
3
Views
409
  • Calculus and Beyond Homework Help
Replies
3
Views
523
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
432
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
5K
  • Calculus and Beyond Homework Help
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
651
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
Back
Top