failure in initial user-supplied objective function evaluation

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 Comments

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) ?
Instead of using
@(u)eval(CHA)
use
matlabFunction(CHA)
This is an efficiency change, but will not solve the problem itself.

Sign in to comment.

Answers (1)

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 Comments

Very Sorry.I have recently Corrected my code.
With the changed version of the code, the limit CHA is
-signum(n)^2*infinity
which is going to be -infinity for any n other than 0.
Notice in your code you have
Kn=besselk(n,w);
Knp=diff(Kn,u);
which differentiates a function of w with respect to u. The result is 0.
Have another look at your
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);
Notice you have 1/w^2. Your CHL asks for the limit of that as w approaches 0. You are therefore asking for a value that approaches 1/0, and the only time that is not going to be infinite (or undefined) is if it is being multiplied by something that goes to 0 in w "faster" so that the limit is 0. But the only places you use w are in 1/w^2 expressions, so there is nothing that is going to 0 "faster". Your entire limit is therefor at the mercy of exactly which infinity or undefined behavior is going to take priority.
sorry.I changed the Knp= diff(Kn,u) to Knp= diff(Kn,w) but it also gave a newer error beyond previous error:''undefined function or variable w''. very thank.
Which line did that error show up on? Did you somehow accidentally not execute the "syms" line?
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.
sorry.is there any problem in answering my new comment.

Sign in to comment.

Categories

Asked:

on 22 May 2015

Commented:

on 24 May 2015

Community Treasure Hunt

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

Start Hunting!