how to transfer expression to myfun using fsolve?
2 views (last 30 days)
Show older comments
Hi, I am trying to solve a system of nonlinear equations. I have the command in a for loop and each time the number of equations changes. So, I decided to create the expressions using 'sprintf' and than go for fsolve.
My function looks now like that:
function P = myfun(start_r)
eval(variables_R) % includes r1 = r(1); r2 = r(2); etc.
eval(equations) % includes P(1) = .....r1 + .....r2^2 - .....; P(2) = ...
So, the error message I receive is: "Undefined function or variable 'variables_R'" which is clear as I have to handle it to myfun.m. How to do that? Where to put variables_R in this expression fsolve(@myfun,start_r)?
Thank a lot for your help in advance. F
0 Comments
Answers (3)
Walter Roberson
on 21 Jan 2013
If you have access to the Symbolic Toolbox, consider describing your system in terms of symbolic variables, and then subs() in any constants you have, and then solve() the system. Or if it is too messy for analytic solutions, using the MuPAD numeric::solve routine.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!