Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the following Taylor series: e^x = sigma_n=0^infinity x^n*n! = 1 + x + x^2/2

ID: 2084770 • Letter: F

Question

For the following Taylor series: e^x = sigma_n=0^infinity x^n*n! = 1 + x + x^2/2! + x^3/3! + x^4/4! + .. i. Write a MATLAB function, named my_f1, that will accept x and n as inputs and produce one output, corresponding to the approximated value of exp(x). ii. Test your function for x = 1 and n = 5. iii. For x = 1, write a MATLAB script that will call this function five times, corresponding to n = 0, 1, 2, 3, and 4. Plot a Bar graph showing the results for all the calls. iv. Plot the error between the exact value and the approximated values for 0 lessthanorequalto n lessthanorequalto 4.

Explanation / Answer

the complete step for the given taylor serires expansion for the matlab function is given step by step in different ways

clear, clc
format long
n = 0 : 4;
x = 1;
d = [0 1 1 1 1];
seq = d .* x.^n ./(factorial(n))
approx = sum(seq)
real_value = sin(x)
******************************
syms x
f=inline('exp(sin(x))')
fc=formula(f); % This is a "character" representation of f for use with fplot.
T4=taylor(f(x),5)
T6=taylor(f(x),7);
a=[0 4];
fplot(fc,a,'k')
title('Plot of f(x)=exp(sin(x), T_4 and T_6')
hold on
gtext('f')
fplot(char(T4),a,'mo')
********************************
fprintf('Taylor series of cos(x) ');
N = input('Enter the number of terms in the expansion: ');
x = input('Enter the value of x to evaluate the function: ');

% Taylor series of cos(x)
approx = 0;
for n=0:N-1
approx = approx + (-1)^n * x^(2*n) / factorial(2*n);
end
fprintf(' ')
fprintf('Taylor series approximation = %.7g ',approx)
fprintf('actual value = %.7g ',cos(x));
fprintf('error = %.3g ',approx-cos(x));