How can I replace an expression in a symbolic function with a new symbolic variable?

23 ビュー (過去 30 日間)
Hello to everyone,
I am using the Symbolic Math Toolbox and, after some steps, I've obtained a very complex symbolic function f. In order to make it easier to read, I'd like to replace some terms of the function with new symbolic variables, but I don't know how.
For example, assuming that the f function is
f = sqrt(A^2 + A*B)
I want to replace the term A*B with a new symbolic variable C, so that
f = sqrt(A^2 + C)
How can I do that? Thanks in advance for your help.

採用された回答

madhan ravi
madhan ravi 2018 年 7 月 6 日
syms A B C
f = sqrt(A.^2+ A*B)
subs(f,A*B,C)
actually this works

その他の回答 (1 件)

Basil C.
Basil C. 2018 年 7 月 4 日
I assume that this should be what you are looking for
function result= C(A,B)
result=A*B;
end
But use this before the function f = sqrt(A^2 + C)
  2 件のコメント
Savino Petrignani
Savino Petrignani 2018 年 7 月 5 日
Actually, I don't have in my code
f = sqrt(A^2 + C)
but only
f = sqrt(A^2 + A*B)
In my complex function, the same expression appears several times and so I need to replace this expression with a new symbolic variable.
Basil C.
Basil C. 2018 年 7 月 6 日
So you mean to say you want to replace the function f ?

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

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by