How to fixe this error with fsolve ?
5 views (last 30 days)
Show older comments
Hello everyone.
I am having trouble to solve a system of two nonlinear equations of two variables with the fsolve command. Here is how I proceed:
- I define a function of 5 variables:
function y = eq2(Par,kl,kf,ml,okt,omt) % Par is structure that contains parameters (constants) of my function
... % lines of instructions
end
The function eq2 works well. For example:
eq2(Par,.5,1,0.1,0.3,0.5)
% gives
ans =
0.0011 -0.9532
- Then I fixe the value of 3 variables and define the function of the two remaining variables:
fun = @(kl,ml) eq2(Par,kl,1,ml,0.3,0.5);
The function fun works as well. For example:
fun(0.5,0.1)
% gives
ans =
0.0011 -0.9532
% same answer as before, as expected
- Then I want to solve the equation fun(kl,ml)=(0,0):
x0 = [0.1,0.1];
solve(fun,x0)
which does not work. I get the error message:
Error using sym.getEqnsVars>checkVariables (line 92)
Second argument must be a vector of symbolic variables.
Error in sym.getEqnsVars (line 56)
checkVariables(vars);
Error in solve>getEqns (line 429)
[eqns, vars] = sym.getEqnsVars(argv{:});
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
I don't understand the error message, and I don't know what is wrong in my code. If the problem were only that solution does not exist the message should be different.
Can someone help me please ? Thank you in advance.
4 Comments
VBBV
on 2 Oct 2020
Use fsolve as
% if true
% code
% end
options = optimoptions('fsolve','Display','iter');
[x fval] = fsolve(fun,x0,options)
Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!