How do I write the function to derive an nth taylor polynomial?

12 ビュー (過去 30 日間)
James T
James T 2017 年 9 月 12 日
コメント済み: James T 2017 年 9 月 13 日
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

採用された回答

James Tursa
James Tursa 2017 年 9 月 12 日
You are using the series expansion for cos( ), not the series expansion for exp( ). You need to replace the terms you are using with the terms that match the series expansion for exp( ).
  1 件のコメント
James T
James T 2017 年 9 月 13 日
for i = 0:n
y = y + (x.^i)./factorial(i);
end
%Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by