how to substitute symbolic variables

14 ビュー (過去 30 日間)
Maaz Nayeem
Maaz Nayeem 2020 年 4 月 14 日
回答済み: Walter Roberson 2020 年 4 月 15 日
hello ,
i want to substitute sin(theta) with theta and cos(theta) with 1 ,
the expression is like
dte1= (Ks*(474.0*te1 - 374.0*te2))/100 - 1.0*L*p*sin(te1) - 1.3*L*p*sin(1.3*te1 - 1.2*te2) - 0.3*L*p*sin(0.3*te1)
I tried "subs" function but it is replacing only the specified variable , i want to replace it like this :
for example : in the above equation i want to replace
sin(1.3*te1 - 1.2*te2) → (1.3*te1 - 1.2*te2)
sin(0.3*te1) → (0.3*te1)
summary : replace sin(theta) with theta , theta can be any symbolic variable

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 14 日
編集済み: Ameer Hamza 2020 年 4 月 14 日
First convert to string. Remove sin and convert back to symbolic expression
syms K2 te1 te2 L p Ks
dte1 = (Ks*(474.0*te1 - 374.0*te2))/100 - 1.0*L*p*sin(te1) - 1.3*L*p*sin(1.3*te1 - 1.2*te2) - 0.3*L*p*sin(0.3*te1);
det1_str = string(dte1);
det1_str = strrep(det1_str, 'sin', '');
dte1 = str2sym(det1_str);
  8 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 4 月 14 日
Check the code for cos() -> 1 function
Maaz Nayeem
Maaz Nayeem 2020 年 4 月 14 日
i got it !
TYSM !!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 4 月 15 日
mapSymType(mapSymType(dte11, 'sin', @(x) children(x)), 'cos', 1)
There might be a way to do both in one call

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by