Function to solve an equation for a given variable

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Timing 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