Approximate Value Using Taylor Polynomial

9 ビュー (過去 30 日間)
codeconstructo
codeconstructo 2023 年 1 月 27 日
編集済み: Torsten 2023 年 1 月 27 日
I have the following problem:
Use MATLAB to help you approximate f(5) using a 10th degree Taylor polynomial centered at
c = 4 for the function f(x) = sin2(x) cos(x).
I keep getting several different errors. The following is different methods I have tried with no luck. When I don't get an error, x is still in the answer. I am trying to find a value after it is evaluated. What can I do to solve this problem?
%1
syms x
f= (sin(x).^2).*(cos(x))
T = taylor(f,x,'ExpansionPoint',4,'Order',10)
%2
syms x
T = taylor((sin(x).^2).*(cos(x)),x,'ExpansionPoint',1)
%3
syms x
f =@(x) (sin(x).^2).*(cos(x))
T = taylor(f(5),'order',10)

採用された回答

KSSV
KSSV 2023 年 1 月 27 日
syms x
f = (sin(x).^2).*(cos(x))
f = 
T = taylor(f,x,'order',10)
T = 
double(subs(T,5))
ans = -1.2435e+04
  2 件のコメント
codeconstructo
codeconstructo 2023 年 1 月 27 日
Thank you. Spent 4 hours for it to be that simple. Nice
Torsten
Torsten 2023 年 1 月 27 日
編集済み: Torsten 2023 年 1 月 27 日
syms x
f = (sin(x).^2).*(cos(x))
f = 
T = simplify(taylor(f,x,'order',11,'ExpansionPoint',4))
T = 
fliplr(coeffs(T)).'
ans = 
double(subs(T,5))
ans = 0.2605
double(subs(f,x,5))
ans = 0.2608

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

その他の回答 (1 件)

Rajeev
Rajeev 2023 年 1 月 27 日
You can first subsitute x in T using the 'subs' function and then use the 'double' to convert the answer to double precision type at the value x. Example:
This script returns a syms variable T,
syms x
f= (sin(x).^2).*(cos(x))
T = taylor(f,x,'ExpansionPoint',4,'Order',10)
substitute x with 5 as in T as given below:
sub_T = subs(T,x,5)
evaluate the value at 5 using the 'double' like:
ans = double(sub_T)
Refer to the documentation for more information:

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by