Multiple roots with fzero, or an alternative to find multiple root

36 views (last 30 days)
Dear MATLAB users, I want to get several roots using "fzero" function. I also tried "chebfun" but I could not run the program. So I would highly appreciate if anyone can give me any advice:
% clear all
clc
N = 100 ;
d = 6 ;
kappa = 1 ;
lambda = linspace(0.05,0.175, N );
nu_p = linspace(0.1,0.35, N );
[Lm,NP] = meshgrid(lambda, nu_p );
cosfi = 1;
f = @(x,lambda,nu_p) ((lambda - nu_p)+(lambda*x)-cosfi.*(((sqrt((1+x)./2)).*exp(-(d*(sqrt(2*lambda*(1+x))))))).*(kappa*(sqrt((1-x)./(1+x)))-(sqrt((1+x)./(1-x )))));
for k1 = 1:length(lambda )
for k2 = 1:length(nu_p )
z(k1,k2) = fzero(@(x) f(x,lambda(k1),nu_p(k2)), 0.000000000001 );
t1 = sqrt(1+(z(k1,k2)));
t2 = sqrt(1-(z(k1,k2)));
q = sqrt(.5).*t1.*exp(-d.*sqrt(2.*lambda(k1)).*t1);
J11 = 0;
J12(k1,k2) = -q.*((1 + kappa)/2).*sqrt(1-(z(k1,k2)).^2);
J21(k1,k2) = lambda(k1) + (1/2).*q.*[(1./(2.*(1 + (z(k1,k2)))))-d.*sqrt(lambda(k1)./(2.*(z(k1,k2))))].*[(1./((1+(z(k1,k2))).^2)).*(t1./t2).*kappa + (1./(1-(z(k1,k2)).^2)).*(t2./t1)];
J22 = 0;
% Eigenvalues
Eig1 = sqrt(J12.*J21);
Eig2 = -sqrt(J12.*J21);
EigReal = real(Eig1);
EigIm = imag(Eig1);
end
end
% DeltaE = Lambda - nu_p;
Z=abs(z);
figure(1 )
mesh(nu_p,lambda, EigReal)
view(2)
% title('kd=6');
xlabel('nu_p');
ylabel('lambda');
zlabel('Z');
When I change "d" 9 or 12 there will be several roots which this code would just find the first one, and I am interested in finding Eigenvalue for those other roots also.
Thanks in advance
  13 Comments
Walter Roberson
Walter Roberson on 11 May 2018
There is at least one point where the function only has a single root. The points at which it does not have a single root: can you guarantee that the number of roots will be the same between all of those points? If not, then the upper left corner might have two roots, A1 and A2, but the lower right might have three roots, B1, B2, B3. If you want three plots because some point on the grid has three roots, then you need to decide what content you want for the places that have different numbers of roots: when you are presenting the third plot, the one that shows the B3 root, then what should be in the upper left corner, which A root? The minimum among all of the A roots? The maximum?
So far I see no evidence that any of your points has anything other than 1 root. I will attach the script after I do another test.
Argumanh
Argumanh on 11 May 2018
Dear Walter,
thank you very much for your attention. The ponit is that, there is a constant named "kappa" which I put it as "1", I am going to use it with the values of 0.2 0.4 0.6 0.8 and 1 . So there may be some points which we get multiple roots. Anyway, I would highly appreciate your help.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 11 May 2018
Script enclosed. You will want to bump up M and N to your 101 each. I did not test that high with this version of the script because it is not fast.
I see no evidence at all that any point has more than one root.
When I was testing the fzero() version, I was able to show that the function under consideration then did not have more than one root for fixed parameters. What I did not do is go back to check to see if the function you are passing to chebfun is the same as the one I investigated earlier.
  13 Comments
Argumanh
Argumanh on 25 May 2018
Dear Walter,
Thank you very much for your time and attention. The parameters that I want to be constant are "d" "cosfi" and "kappa" and the variables would be "Lambda" and "DeltaE". In addition to that, I want to know the Value or the magnitude of the roots. For example we have Eigenvalues for first root plotted in the 3D(eigroot2.m) I want to know the magnitude of the root which gave me that 3D plot.
Best,
Armin
Walter Roberson
Walter Roberson on 25 May 2018
In the eigroot3 code I posted yesterday, I do not attempt to find exact roots: the pair of lines
T = sign(gFd);
zc = sum(T(:,:,1:end-1) ~= T(:,:,2:end),3);
looks for sign changes along the z dimension.
How precise do you need to z values? At present the code does a grid search with numz samples taken over -1 to +1 . Is that good enough, or do you need the root to a number of decimal places? If you do then it would probably make the most sense to use the approximate zeros (detected by sign change) to create upper and lower bounds for a numeric root finder.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!