How to fix Failure in initial objective function evaluation

9 ビュー (過去 30 日間)
Marek Majkut
Marek Majkut 2018 年 4 月 8 日
コメント済み: Walter Roberson 2018 年 4 月 8 日
Hello, I'm trying to evaluate function
f_gamma_r_delta_v = @(x,beta) [...
Px+Q*cos(phi0+beta)+x(2)*cos(gamma0+x(1));
Q*sin(phi0+beta)+x(2)*sin(gamma0+x(1));
S*cos(gamma0+x(1))+U*cos(delta0+x(3))+Wx;
S*sin(gamma0+x(1))+U*sin(delta0+x(3))+x(4)];
using fsolve
[x,fval]=fsolve(f_gamma_r_delta_v,x0,options,beta);
gamma(i)=x(1)*180/pi;
R(i)=x(2);
delta(i)=x(3)*180/pi;
V(i)=x(4);
x0=x;
but I can not fix the Failure in initial objective function evaluation although I've read some answered questions.
Error in fsolve (line 230)
Thank you very much for help.
Marek

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 4 月 8 日
You would get a failure if:
  • Failure if any of the variables other than x in your f_gamma_r_delta_v are not scalars
  • exception: if Q is a row vector and phi0+beta is a column vector of the same length, their algebraic product would be a scalar, which would work
  • Special emphasis: you are going to have a failure if any of those variables are empty. This is a common failure mode when the variables turn out to be globals
  • Failure if any of those variables are nan or inf
  • Special emphasis: 0 times +/- inf is nan, which is a failure. 0 times inf is not 0!
  • Sometimes rotation matrices are just inconsistent and you cannot solve them
  • Except for the last couple of releases, failure if complex values result; the newest couple of releases can fsolve() on complex-valued expressions
I notice, by the way, that the code after that uses i as a vector index. Be careful: by default i is sqrt(-1) . To avoid confusion and make sure you do not accidentally index at sqrt(-1) it is better practice to avoid using i or j as variable names.

Marek Majkut
Marek Majkut 2018 年 4 月 8 日
Thank you for your answer.
All of my variables are real scalars (I checked it in the Workspace).
First beta equals 0, but this should not be a problem.
Non of the variables is empty, nan or inf (checked in the Workspace).
My script is too long so I don't want to send it whole. I'll try to fix it, but thank you for your answer anyway.
I wish you a nice day.
Marek
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 8 日
You could run the code up to that point and save the variables in a .mat file and attach that with minimal code to reproduce the problem from there.
By the way, please see
You are using an undocumented feature of fsolve when you pass in beta the way you are.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by