function handling and calling
2 ビュー (過去 30 日間)
古いコメントを表示
I have created two different function handles containing multiple variable. Say f1(x,t,H,T,bed_level) and f2(x,t,bed_level). In general f1 and f2 are general expressions. bed level is function of x and t. Now i called each function once for different expression of bed_level and stored in A and B.
Say A= f1(x,t,H,T,x*t) %for bed_level =x*t
and, B=f2(x,t,2*x) %for bed_level=2*x*t^2.
Now when i am multipling C= A.*x+B.*t, i am expecting a simplified and solved expression that is function of variables x,t,H,T. But Matlab is not producing a simplified one. It is writing it as it. For e.g (x*t)-t*(x) should cancel out each other but it is writing it as same (x*t)-t*(x)
Kindly help.
4 件のコメント
Sargondjani
2021 年 1 月 22 日
If you use H as an input, when creating a function handle, then it will treat H as a parameter (so the value of H(x)). I guess you need to explicitly calculatue H(x) inside A.
Im not really an expert on this, so I hope someone else steps in :/
回答 (2 件)
Walter Roberson
2021 年 1 月 25 日
編集済み: Walter Roberson
2021 年 1 月 25 日
For e.g (x*t)-t*(x) should cancel out each other but it is writing it as same (x*t)-t*(x)
There are two possibilities that can cause that:
1) one of the x or t is not the same variable as the other one. Symbolic variables are internally not global variables but rather local ones, and you can get a local copy of one returned. For example suppose you are in the middle of a function building a formula that involves
syms x positive
and you call myfun(x) that is
function r = myfun(y)
syms x negative
r = solve(x^2 + 5*y - 6)
You are passing in x assumed positive to myfun that receives it as y and works with x assumed negative. Is the x that is inside y the same x as syms x negative? If it is, then does adding the assumption of negative have the side effect of changing the assumption on the x that lives in the outer function? Or would there be an error about conflicting assumptions? Or would it treat it as two different variables that just happen to display the same way? To be honest, matlab sometimes makes some bad choices as to what actually happens, but inside the symbolic engine itself some of the choices are different and if you tickle it the right way then you can get different variables with the same display
2) one of the x or t might be a symbolic function but the other one might be regular variable. It is easier to provoke matlab into a clash, especially if you sym() or str2sym an expression.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Variables, Expressions, Functions, and Preferences についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!