failure in initial user-supplied objective function evaluation
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 22 Mai 2015
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
le 22 Mai 2015
Instead of using
@(u)eval(CHA)
use
matlabFunction(CHA)
This is an efficiency change, but will not solve the problem itself.
Réponses (1)
Walter Roberson
le 22 Mai 2015
0 votes
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 commentaires
nima salyani
le 22 Mai 2015
Walter Roberson
le 22 Mai 2015
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.
Walter Roberson
le 22 Mai 2015
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.
nima salyani
le 23 Mai 2015
Walter Roberson
le 23 Mai 2015
Which line did that error show up on? Did you somehow accidentally not execute the "syms" line?
nima salyani
le 23 Mai 2015
nima salyani
le 24 Mai 2015
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!