How do I simplify a function?

10 ビュー (過去 30 日間)
Danielle
Danielle 2023 年 1 月 25 日
コメント済み: Dyuman Joshi 2023 年 1 月 25 日
Part of one of my assignments is to simplify this equation:
I put this code into MATLAB:
Treatment= simplify(A-2*(B)+2*(B*Y)+(B/2)-A+(B/2)*(3-(4*Y))-(3*Y*B)+(3*B*A*C)+(C/B)*(sqrt((B^2)*(1/C)*(C+A+(7*C*B)-A))))
but i keep recieving this error:
Error using /
Matrix dimensions must agree.
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 1 月 25 日
Use element-wise operations (.* , ./ and .^) for arrays.
Also, what is the data type of A, B, C and Y? Numeric or symbolic?

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

回答 (1 件)

Star Strider
Star Strider 2023 年 1 月 25 日
You apparently defined some of those variables as arrays previously.
To use the simplified function numerically, use the matlabFunction function, and then present the arrays to it (that have the appropriate dimensions for the necessary calculations) as arguments —
syms A B C Y
Treatment= simplify(A-2*(B)+2*(B*Y)+(B/2)-A+(B/2)*(3-(4*Y))-(3*Y*B)+(3*B*A*C)+(C/B)*(sqrt((B^2)*(1/C)*(C+A+(7*C*B)-A))), 500)
Treatment = 
TreatmentFcn = matlabFunction(Treatment)
TreatmentFcn = function_handle with value:
@(A,B,C,Y)B.*(Y-A.*C).*-3.0+(C.*sqrt(B.^2.*(B.*7.0+1.0)))./B
See if that does what you want. (The 500 argument tells simplify to keep simplifying until it can no longer simplify the function, up to 500 iterations.)
.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by