Question

Convince yourself that the Maclaurin Series for cos(x) is:

2k (2k)! k-0 (N-term approximation)

A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial()

B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees for Cos(x) where 0<x<360. Display a Table using fprintf() display a Table with thirteen rows (0, 30, 60, 90, . . . . . ., 360) and five columns (x in Degrees, 2,3,4,5, and 6-term computations) for comparison.

You MUST NOT use the MATLAB built-in function, table()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

%%%%%%%%%%%%%%%%%%%%%%%% Part A

function Cos_x=cos_series(x,N)
format long
s = 0;
for k = 0: N % need more code here

s =s+(-1)^k*(x^(2*k)/factorial(2*k));

end
Cos_x=s;

%%%%%%%%%%%%%%%%%%%%%%%% Part B

clc;
clear all;
n=0:30:360;
for i=1:13
x(i)=n(i)*pi/180;
end
disp(' x in deg 2-terms 3-terms 4-terms 5-terms 6-terms')
disp('_______________________________________________________________________________________________')
for i=1:13
fprintf('%f \t %10f \t %10f \t %10f \t %10f \t %10f\n \n',n(i),cos_series(x(i),2),cos_series(x(i),3),cos_series(x(i),4),cos_series(x(i),5),cos_series(x(i),6))
end

%%%%%% Solution

x in deg 2-terms 3-terms 4-terms 5-terms 6-terms
_______________________________________________________________________________________________
0.000000    1.000000    1.000000    1.000000    1.000000    1.000000

30.000000    0.866054    0.866025    0.866025    0.866025    0.866025

60.000000    0.501796    0.499965    0.500000    0.500000    0.500000

90.000000    0.019969    -0.000895    0.000025    -0.000000    0.000000

120.000000    -0.391525    -0.508749    -0.499567    -0.500015    -0.500000

150.000000    -0.469620    -0.916796    -0.862066    -0.866234    -0.866017

180.000000    0.123910    -1.211353    -0.976022    -1.001829    -0.999900

210.000000    1.802451    -1.564583    -0.756878    -0.877438    -0.865168

240.000000    5.054553    -2.447829    -0.097177    -0.555448    -0.494533

270.000000    10.443925    -4.765552    1.265714    -0.222441    0.027914

300.000000    18.609439    -10.009876    4.001102    -0.266886    0.619548

330.000000    30.265128    -20.435735    9.598041    -1.472020    1.309990

360.000000    46.200185    -39.256632    20.988009    -5.438247    2.465289

>>

Add a comment
Know the answer?
Add Answer to:
Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1...

    In MATLAB The value of cos(x) can be approximated using a Maclaurin series + +... cos(x)=1-1 2! 4! 6! Which can be expressed compactly as cos(x) = {(-1)+7 (2(k-1))! 00 2(k-1) k-1 Write Matlab code using a while loop that calculates cos(2) with 5 terms of Maclaurin series. Compare the value with the one calculated with a built-in function cos (2) in Matlab. The following is an expected output from your code: Using the Maclaurin series cos( 2.0) with 5...

  • 8. The Maclaurin series (a special case of the Taylor series that is discussed later in...

    8. The Maclaurin series (a special case of the Taylor series that is discussed later in this class) allows us to express a differentiable, analytic function as an infinite degree polynomial. Here is the degree seven polynomial approximation of the sine: x3 x5 x? 3! 5! 7! + Use Matlab to generate a plot of sin(x) (solid blue line) and its polynomial approximation (dashed red line) for x = 0 to 31/2 and y from -1.5 to 2. Use the...

  • I want to create a Matlab function of the maclaurin series of cos(x), which depends on...

    I want to create a Matlab function of the maclaurin series of cos(x), which depends on x and tol, and plot the function for -Lx<=x<=Lx where Lx is a user specified input.

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • The function g has derivatives of all orders, and the Maclaurin series for g is Question 1 (5 poi...

    The function g has derivatives of all orders, and the Maclaurin series for g is Question 1 (5 points) Using the ratio test, determine the interval of convergence of the Maclaurin series for . Question 2 (2 points) The Maclaurin series for g evaluated at Z-可is an alternating series whose terms decrease in absolute value to 0. The approximation for g ( using the first two nonzero terms of this series is 120 Show that this approximation differs from 9...

  • 7. (a) Use the well known Maclaurin series expansion for the cosine function: f (x )...

    7. (a) Use the well known Maclaurin series expansion for the cosine function: f (x ) = cos x = 1 x? 2! + 4! х 6! + (-1)" (2n)! . * 8! 0 and a substitution to obtain the Maclaurin series expansion for g(x) = cos (x²). Express your formula using sigma notation. (b) Use the Term-by-Term Integration Theorem to obtain an infinite series which converges to: cos(x) dx . y = cos(x²) (c) Use the remainder theorem associated...

  • An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+...

    An alternative way for calculating sin(x) is to use its Taylor series as the following: sinx)x-+ Create a function named "sin_taylor" in MATLAB. This function takes two inputs. First input is the angle, and the second input determines the number of terms in Taylor series for approximation. Check the fidelity of your function by running sin-taylor( 7) and compare it with the exact value of it. Hint: “factorial" is a built-in function that you can use for calculating factorial of...

  • 1) Write a script that plots sin(x), cos(x), tan(x) for x between 0 and 360◦ (or...

    1) Write a script that plots sin(x), cos(x), tan(x) for x between 0 and 360◦ (or 2π radians) on one graph, adjusts the y axis to range between −10 and +10, and includes a legend identifying each line. 2)Write a Matlab function that sums up a specified number of odd-power terms from the Maclaurin series of sin(x) For example, if you use the function you wrote to sum the first 10 terms for x = 1, you should get 1...

  • MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value...

    MATLAB Use the Taylor series cos(x)-1-to compute cos(x) to four decimal places (by comparing the value with the matlab built-in function for cos). How many iterations does it take to get to 4- decimal place agreement? (hint: help factorial) 2! 4! 6!

  • Write the Maclaurin series for f(x)=8cos4x2 as n=0cnxn Find the following coefficients. Write the Maclaurin series...

    Write the Maclaurin series for f(x)=8cos4x2 as n=0cnxn Find the following coefficients. Write the Maclaurin series for f(x) = 8 cos(4x) as Conten. n=0 Find the following coefficients. II Co C2 = C4 C6 = Cg =

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT