フィルターのクリア

How to fixe this error with fsolve ?

1 回表示 (過去 30 日間)
Idossou Marius Adom
Idossou Marius Adom 2020 年 10 月 1 日
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 件のコメント
VBBV
VBBV 2020 年 10 月 2 日
Use fsolve as
% if true
% code
% end
options = optimoptions('fsolve','Display','iter');
[x fval] = fsolve(fun,x0,options)
Idossou Marius Adom
Idossou Marius Adom 2020 年 10 月 2 日
Thank you very much J. Alex Lee and Vasishta Bhargava. It works now.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by