Question

Please show exactly how it is in MATLAB The cosine function can be evaluated by the...

Please show exactly how it is in MATLAB

The cosine function can be evaluated by the following infinite series: cos ? = 1 − ?^2/ 2! + ?^4/ 4! − ?^6 /6! + ⋯ Create an M-file to compute cos(1.2345 rad) for up to and including eight terms, which is up to the term x^14/14!.

a) Your program should compute and display the values of cos ? as each term in the series is added, e.g.

cos ? = 1

cos ? = 1 − ?^2/ 2!

cos ? = 1 − ?^2 /2! + ?^4/ 4!

b) Compute and display the true relative error as a percentage ?? = true value−series approximation true value × 100%

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

ANS:

CODE:

clc;
clear all;
close all;
n=input(' Enter the number of terms u want in expantion ');
% % let x= pi/6
x=pi/3;
sum=0;
for k=0:n
sum=sum+(-1)^k*x^(2*k)/factorial(2*k);
cosx=sum;
cosx
p_err=abs(cos(x)-cosx)/cosx*100
  
end

output:

Enter the number of terms u want in expantion 3

cosx =

1


p_err =

50.0000


cosx =

0.4517


p_err =

10.6957


cosx =

0.5018


p_err =

0.3580


cosx =

0.5000


p_err =

0.0071

IF YOU HAVE ANY DOUBTS COMMENT BELOW RATE THUMBSUP PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

Add a comment
Know the answer?
Add Answer to:
Please show exactly how it is in MATLAB The cosine function can be evaluated by the...
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
  • The cosine function can be evaluated by the following infinite series as (where the angle x...

    The cosine function can be evaluated by the following infinite series as (where the angle x is given in radians) cos x =1--+ + 2! 4! 6! Create a second function M-file mycos that takes the angle x (in radians), and returns cos(x) with an absolute iterative error less than 1.0e-18. Test your function to find cosine of ?/2 and 2? Display the Expansion order, and the actual error (absolute error, not the relative one) and iterative error using fprintf...

  • 3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be...

    3. Cosine Approximation Write a function m-file to calculate the approximated cosine function which can be evaluated by the following infinite series - equation (2): 1. x² x4 26 (-1)(n+1). 22(n-1) cos x = 1 - 3 + - 6! + + (2(n − 1))! Here are requirements for the function m-file. - Parameter lists (inputs): 2 value (in radian), and desired error percentagel. - Return value (outputs): approximated value, real error percentage, and number of iterations - Function name:...

  • The natural log of 2, (In 2) can be found using the power series below: In...

    The natural log of 2, (In 2) can be found using the power series below: In 2 1- Create an M-file function to implement this formula so that it computes and displays the values of In 2 as each term in the series is added. In other words, compute and display in sequence the values for up to the order term, n, as chosen by the user of the function. For each of the preceding, compute and display the percent...

  • 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...

  • Instructions: Submit your script in a file named hwk08.m to the dropbox before 11:59 pm on the du...

    Instructions: Submit your script in a file named hwk08.m to the dropbox before 11:59 pm on the due date NOTE: This assignment is neither quick nor simple. You will be well served to start on it early, and to ask for help if you need it. Being a more substantial assignment than earlier hwk, it is worth- s. When you ask your calculator for the value of a function for a specified argument, (e.g., sin(22), cos(74), In(6.5)), it almost certainly...

  • 2. The following integral 2 dr can be computed exactly (a) Estimate the integral using the...

    2. The following integral 2 dr can be computed exactly (a) Estimate the integral using the composite trapezoidal rule with n = exact value of integral and compute the true percent relative error for this approximation 4. Calculate the (b) How many subintervals would be needed to estimate the integral with the composite trapezoidal rule with an accuracy of 102? (c) Estimate the integral using the composite Simpson's 1/3 rule with n = true percent relative error for this approximation...

  • Please show the full steps! 3. Find the MacLaurin series for f(x)cos(). Beginning with the first term of the series, add terms one at a time to estimate cos(.257). a) After adding each term, compute...

    Please show the full steps! 3. Find the MacLaurin series for f(x)cos(). Beginning with the first term of the series, add terms one at a time to estimate cos(.257). a) After adding each term, compute the true and the approximate percent relative errors b) Continue the iterative process of adding one term at a time until the approximate percent relative error falls below an error criterion for 4 significant figures (by hand). 3. Find the MacLaurin series for f(x)cos(). Beginning...

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: 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...

  • wnloads/HW5 pdf Create a MATLAB code to calculate function f (z) = ei8r at any given...

    wnloads/HW5 pdf Create a MATLAB code to calculate function f (z) = ei8r at any given point using Taylor series. Write a script file called myTaylor.m and a function file called myFact.m to do the following: (a) The function myFact.m should return the factorial of a number when sent the number. In the script file: i. Set the starting point as r0-1 and fo = f(d)-6.049647 ii. Ask the user to enter his/her desired point and store it in x1...

  • Write a regular function (i.e. in a function .m file) to calculate the series expansion of...

    Write a regular function (i.e. in a function .m file) to calculate the series expansion of cosine(x). The number of terms calculated in the series should be specified in the input list of the function. Write a separate function that determines when the series expansion begins to deviate by at least 10% from the true value of cosine(x) based on the number of terms calculated in the series expansion, n. For n = 1, 2, … 10, determine the values...

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