Question

1. Write a MATLAB script, by hand, on this page, that calculates the nth degree Taylor...

1. Write a MATLAB script, by hand, on this page, that calculates the nth degree Taylor expansion of cos x and then compares the plot of this expansion to the original function. In one of your first lines, you may fix n (e.g., n = 6) but the remainder of the code should refer to n.

Homework Answers

Answer #1

MATLAB Script:

close all
clear
clc

n = 6;

syms x
f = cos(x);
Tn = taylor(f, x, 'Order', n + 1);
disp('Taylor Expansion:'), disp(Tn)

xx = 0:0.01:2*pi;
yy_exact = cos(xx);
yy_taylor = subs(Tn, xx);
plot(xx, yy_exact, xx, yy_taylor)
legend('cos(x)', 'Taylor Expansion', 'Location', 'southwest')
xlabel('x'), ylabel('y'), title('Taylor Expansion of cos(x)')

Output:

Taylor Expansion:
- x^6/720 + x^4/24 - x^2/2 + 1

Plot:

Know the answer?
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
Similar Questions
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x) . exp(sin x), Using numerical integration method. When the user runs the script, he/she is prompted to input the lower and upper limits for numerical integration, both in radians, and your program outputs the integration result. You can use built-in trigonometric functions and the exponential function, but you are not allowed to use any built-in function to do the integration. You must use a...
1. Find T5(x): Taylor polynomial of degree 5 of the function f(x)=cos(x) at a=0. T5(x)=   Using...
1. Find T5(x): Taylor polynomial of degree 5 of the function f(x)=cos(x) at a=0. T5(x)=   Using the Taylor Remainder Theorem, find all values of x for which this approximation is within 0.00054 of the right answer. Assume for simplicity that we limit ourselves to |x|≤1. |x|≤ = 2. Use the appropriate substitutions to write down the first four nonzero terms of the Maclaurin series for the binomial:   (1+7x)^1/4 The first nonzero term is:     The second nonzero term is:     The third...
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method...
10.16: Write a user-defined MATLAB function that solves a first-order ODE by applying the midpoint method (use the form of second-order Runge-Kutta method, Eqs(10.65),(10.66)). For function name and arguments use [x,y]=odeMIDPOINT(ODE,a,b,h,yINI). The input argument ODE is a name for the function that calculates dy/dx. It is a dummy name for the function that is imported into odeMIDPOINT. The arguments a and b define the domain of the solution, h is step size; yINI is initial value. The output arguments, x...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits...
Write a MATLAB function and test bench script code to solve the above simple RL/RC circuits by following the instructions noted below. The input signal and impulse response generation should be done in the function. The test bench script should be used only to call the function and for signal plotting purposes. No plotting should be done inside the function itself. Name your function L2_C Instructions: Input voltage ,x(t), can be AC or DC. Consider a variable ‘w1’ which can...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...