failure in initial user-supplied objective function evaluation

조회 수: 1 (최근 30일)
nima salyani
nima salyani 2015년 5월 22일
댓글: nima salyani 2015년 5월 24일
sorry. I want to solve an equation with fsolve, but it just solve for n=0 and for others gives this error:
failure in initial user-supplied objective function evaluation. Fsolve cannot continue.
the code is:
c=3.8;
ncl=3; nc=3;
syms u w n
Jn=besselj(n,u);
Jnp=diff(Jn,u);
Kn=besselk(n,w);
Knp=diff(Kn,w);
J0=Jnp/(u*Jn);
K0=Knp/(w*Kn);
CH=(J0+K0)*(J0+(ncl/nc)^2*K0)-n^2*(1/u^2+1/w^2)*(1/u^2+(ncl/nc)^2*1/w^2);
CHL=limit(CH,w,0);
x0=(3);
for m=0:9
CHA=subs(CHL,n,m);
options = optimoptions('fsolve','Display','iter'); % Option to display output
fval= fsolve(matlabFunction(CHA),x0,options) % Call solver
end
can enyone help me.
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 5월 22일
What is nc? You have ncl/nc twice, but you do not define nc. Is it n*c ? Should ncl/nc be read as (ncl/n)*c, or as ncl/(n*c) ?
Walter Roberson
Walter Roberson 2015년 5월 22일
Instead of using
@(u)eval(CHA)
use
matlabFunction(CHA)
This is an efficiency change, but will not solve the problem itself.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 22일
Your limit is signum(EXPRESSION)*infinity and so can only be 0 if EXPRESSION is 0 and if you give 0*infinity a definite meaning as being 0 instead of being undefined. Logically solving for signum(EXPRESSION)*infinity = 0 with 0*infinity being defined as 0 is the same as solving for EXPRESSION = 0, but is much more fragile at the best of times, since almost all of the results are going to be +/- infinity and when you finally get a different result it is the exact solution. And then there is the problem that MATLAB is going to return NaN for 0*inf when the signum is finally 0, so fsolve() is not going to be able to find that answer either.
The difficulty of finding the roots of EXPRESSION will depend upon what your "nc" means. Under at least one of the potential meanings, n=0 is a root, which is why you get a solution when n = 0; the solution is independent of the u, so if you are counting on any particular u result as being numerically meaningful, you should not be.
  댓글 수: 7
nima salyani
nima salyani 2015년 5월 23일
I am sure execution include syms line. first it gives a warning ''Function''limit'' is not vrrified to be a valid matlab function'' and then the error I have said recently and the first error I've asked you. thank a lot.
nima salyani
nima salyani 2015년 5월 24일
sorry.is there any problem in answering my new comment.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by