function y = nthTaylorPolyExp( n, x )%y = nthTaylorPolyExp( n, x )is a function that returns 3rd Taylor polynomial of exponential function at x=0.
% n is an input argument, which indicates the degree of Taylor
% polynomial.
% x is an input argument
% y is output.
y=zeros('like',x);% ============= YOUR CODE HERE ==============
% Instructions: Return nth Taylor polynomial of exponential function at x=0.
% You can use built in function factorial(n) to return n!,
% and use for loop to get the sum.
for i = 0:n % y = y + (-1)^i * (x.^(2 * i)) / factorial(2 * i); is my version, but its incorrect.
end% ===========================================
end
MATLAB: How to write the function to derive an nth taylor polynomial
homeworkoptional
Best Answer