how to transfer expression to myfun using fsolve?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Walter Roberson
2013-1-21
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!