フィルターのクリア

Problem with fsolve and nonlinear equations

1 回表示 (過去 30 日間)
Henn
Henn 2017 年 7 月 31 日
回答済み: Walter Roberson 2017 年 8 月 1 日
I have attached my script file and function file. The error message I keep receiving is this:
Error in fsolve (line 230) fuser = feval(funfcn{3},x,varargin{:});
Error in Code (line 34) vars = fsolve(@fffRoinvof,vars0,opts,beta1,beta2,alpha,H,F,rho,S12,S21);
Caused by: Failure in initial objective function evaluation. FSOLVE cannot continue. I can't seem to figure out what is going on and why I'm receiving this error. I took this code from a book and wanted to see how it would run and the results I would see. Thanks in advance for your help
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 8 月 1 日
Please recheck your line
z=@(y) (beta1-beta2)*a12*y.^beta2_(beta1-1)*y/(rho-alpha)-beta1*(H*F/rho+I);
in Code.m . Notice the underscore. I suspect it should be a minus,
z=@(y) (beta1-beta2)*a12*y.^beta2-(beta1-1)*y/(rho-alpha)-beta1*(H*F/rho+I); %recheck this!

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

回答 (2 件)

Star Strider
Star Strider 2017 年 7 月 31 日
You are not calling fsolve correctly with your function.
Try this:
vars_out = fsolve(@(vars) fffRoinvof(vars,beta1,beta2,alpha,H,F,rho,S12,S21), vars0, opts);
a12 = vars_out(1);
a21 = vars_out(2);
xi12 = vars_out(3);
xi21 = vars_out(4);
I did not run your code, so there could be other problems. The fsolve problem was obvious.
  2 件のコメント
Henn
Henn 2017 年 7 月 31 日
編集済み: Henn 2017 年 7 月 31 日
If I run your code in my code.m file it gives the following error message:
Error in Code (line 34) vars_out = fsolve(@(vars) fffROinvof(vars,beta1,beta2,alpha,H,F,rho,S12,S21), vars0, opts);
Caused by: Failure in initial objective function evaluation. FSOLVE cannot continue.
and in the fffROinvof file:
Not enough input arguments.
Error in fffROinvof (line 4) a12=vars_out(1); ---- which is the same error message as before for this file
Star Strider
Star Strider 2017 年 7 月 31 日
This runs for me without error (after I corrected a syntax error in your function, since ‘ai12’ does not exist, but ‘a12’ does):
Corrected Function:
function f=fffROinvof(vars,beta1,beta2,alpha,H,F,rho,S12,S21)
a12=vars(1);
a21=vars(2);
xi12=vars(3);
xi21=vars(4);
f=zeros(4,1);
f(1)=a12*xi12^beta2+xi12/(rho-alpha)- H*F/rho-a21*xi12^beta1+S12;
f(2)=beta2*a12*xi12^(beta1-1);
f(3)=-a21*xi21^beta1+...
1/(rho-alpha)-H*F/rho+a12*xi21^beta2-S21;
f(4)=-beta1*a21*xi21^(beta1-1)+...
1/(rho-alpha)+beta2*a12*xi21^(beta2-1);
end
The function call I posted earlier works correctly:
vars_out = fsolve(@(vars) fffROinvof(vars,beta1,beta2,alpha,H,F,rho,S12,S21), vars0, opts);
You may want to increase the number of function evaluations and iterations.

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


Walter Roberson
Walter Roberson 2017 年 8 月 1 日
I took a copy of your code and fixed up some of the mistakes (you had several typos.)
I ran the code until the point of the fsolve, and then at the command line I called fffRoinvof with a symbolic vector [v1, v2, v3, v4] for vars, and numeric values for the other parameters. The result is a system of four equations in the four variables in vars.
When I examine the system of variables, by doing step-by-step elimination of the variables, I can find expressions for v1, v2, v4 in terms of v3, and those expressions for v1, v2, v4 do not themselves force those variables to be complex valued. However, when you then examine the remaining equation, after all the other substitutions, then the only way it can equal zero is if v3 is complex-valued. Then because the other equations are in terms of v3, the others come out complex-valued as well.
If you then manage to get fsolve() to give you an answer, the answer would be complex-valued.
You then construct some values with the returned vars, and you construct z using some of them; because some of them are complex-valued at this point, z() is generally going to be complex-valued. You then fzero() on z. However, fzero cannot work with complex-valued functions, so you are stuck.
I did some investigation, and find that the problem is not with the alpha values -- varying those gives equations that still have no real roots for v3.

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by