failure in initial user-supplied objective function evaluation

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 22 Mag 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
Walter Roberson il 22 Mag 2015
Instead of using
@(u)eval(CHA)
use
matlabFunction(CHA)
This is an efficiency change, but will not solve the problem itself.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 22 Mag 2015
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 Commenti
nima salyani
nima salyani il 23 Mag 2015
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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by