Fsolve converges to a point which is not a root and returns wrong fval

3 views (last 30 days)
I have a code which takes a point in the complex plane as input and uses it as an initial guess to find the roots of a nonlinear equation. The fval returned by fsolve is of the order of 1.0e-07 with positive exitflag. but when i put the roots obtained by fsolve into the equation i am getting a vlaue of the order of 1.0e+06. All i am doing is copying the fn in fsolve and separetely working out the value. I have attached my code herein. any help is appreciated.
%k_max is root no.
while k<=k_max
grid on;
[c,b]=ginput(1);
j=sqrt(-1);
real_ini=c;
imag_ini=b;
x0=[c,b];
options = optimoptions('fsolve','TolFun',1.1e-16,'TolX',1.1e-16,'maxIter',Inf,'MaxFunEvals',Inf);
[num_roots,fval,exitflag]=fsolve(@coupled_dispersion2,[real_ini,imag_ini],options)
if(isempty(find(round(xe*1e4)*1e-4==round(complex(num_roots(1),num_roots(2))*1e4)*1e-4,1))==1) && num_roots(2)>=0
xie=complex(num_roots(1),num_roots(2));
if exitflag>0
xe(k)=xie1;
xi=sqrt(Omega^2*cl^2/cfi/cfi-xe(k)^2);
x=(Omega^2*cl^2/cfe^2-xie^2);
xit=sqrt(Omega^2*cl^2/cfi^2-x1(k)^2);
det(k)=abs((Omega^2-x)*((Omega^2-1-beta^2*x^2)*(besselh(1,1,xie)*xie)*(besselj(1,xi)*xi)...
-Omega^2*(rhofi*a/rhos/h)*(besselj(0,xi)*(besselh(1,1,xie)*xie))+Omega^2*(rhofe*a/rhos/h)*(besselj(1,xi)*xi)*(besselh(0,1,xie)))...
-nu^2*x*(besselh(1,1,xie)*xie)*(besselj(1,xi)*xi));
[det(k)]
xie1
k=k+1;
end
hold on
if exitflag>0
plot(num_roots(1),num_roots(2),'*g');
else
plot(num_roots(1),num_roots(2),'*r');
end
end
end
the coupled_dispersion2 file is
function [root_new]=coupled_dispersion2(kappa_com)
global cl cfi cfe Omega beta rhofi rhofe rhos nu a h
kappa=complex(kappa_com(1),kappa_com(2));
kappa;
x=(Omega^2*cl^2/cfe^2-kappa^2);
xi=sqrt(Omega^2*cl^2/cfi^2-x^2);
fn=abs((Omega^2-x)*((Omega^2-1-beta^2*x^2)*(besselh(1,1,kappa)*kappa)*(besselj(1,xi)*xi)...
-Omega^2*(rhofi*a/rhos/h)*(besselj(0,xi)*(besselh(1,1,kappa)*kappa))+Omega^2*(rhofe*a/rhos/h)*(besselj(1,xi)*xi)*(besselh(0,1,kappa)))...
-nu^2*x*(besselh(1,1,kappa)*kappa)*(besselj(1,xi)*xi)) ;
root_new=[real(fn);imag(fn)];

Answers (0)

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!