필터 지우기
필터 지우기

Function to solve an equation for a given variable

조회 수: 2 (최근 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 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