Function to solve an equation for a given variable

1 回表示 (過去 30 日間)
Simone Pagliuca
Simone Pagliuca 2022 年 11 月 22 日
編集済み: John D'Errico 2022 年 11 月 22 日
I would like to have a function like f(a,b,c,d,e) which I could call multiple times in my code but to be solved for different variables:
ans1 = f(X,b,c,d,e) it solves for the first variable, I set the other 4
ans2=f(a,b, X, d, e) solves for the third, I set the other 4
and so on.

採用された回答

John D'Errico
John D'Errico 2022 年 11 月 22 日
編集済み: John D'Errico 2022 年 11 月 22 日
If it is symbolic problem, then it is trivial. Just assign those variables, subs them in, and use solve. WTP?
If it is a numerical problem, then just create a function handle with the one variable as an unknown.
In either case, it is trivial. So WTP?
Could you get fancier, and write a wrapper function, where you pass it in the variables you want to assign, and tell it which variable is to be solved for? Yes. Go for it. Write the code, then post it on the File Exchange. If you manage to do so with a wonderfully clean interface, others will find it useful. If you can't write that clean interface, then don't waste your time, as the above solutions are so easy to implement. And since I and others have never seen a reason to bother to come up with a nice function to do something like this that I know of, it suggests that many other authors agree with me. But go for it.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by