How to get Taylor polynomial for functions?

7 ビュー (過去 30 日間)
Carter Wunch
Carter Wunch 2021 年 4 月 19 日
回答済み: Rafael Hernandez-Walls 2021 年 4 月 19 日
I'm looking to write a program where i can input a function, like exp(x) or sin(x), and have the program return the Taylor polynomials for the function.
This is what I have so far. I am fairly new to Matlab and am still getting used to the software.
str=input('Function? ','s');
T=taylor(s);
sympref('PolynomialDisplayStyle','ascend');
disp T

採用された回答

Rafael Hernandez-Walls
Rafael Hernandez-Walls 2021 年 4 月 19 日
You can use a function that is in the MAThWORKS fileexchange (I put the link):
str=input('Function? ','s'); %tray with: cos(x)
% https://la.mathworks.com/matlabcentral/fileexchange/67519-str2syms-symstr
z = str2syms(str)
T=taylor(z)
%
T =
x^4/24 - x^2/2 + 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by