I'm getting the message:
FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.
I am also getting results and the plot that I get is acceptable, but I want to know: does the problem described in the message influence the results? Or can I continue?
e1=1; e2=-1; e3=3.0625; e4=-1; e5=1; lam=632.8*10^-9; c=3*10^8; w=2*3.14*c/lam; m1=1; m2=-1; m3=1; m4=-1; m5=1; d2=60*10^-9; d4=60*10^-9; f=0.5; j=2;
k0=w/c;
m = 0;
Wi = 150 ; Wf = 500; Wstep = 10;
nf = (Wf - Wi)/Wstep + 1
q3 = Sqrt[(k0^2*e3*m3) - B^2];
q1 = Sqrt[B^2 - (k0^2*e1*m1)];
q2 = Sqrt[B^2 - (k0^2*e2*m2)];
q4 = Sqrt[B^2 - (k0^2*e4*m4)];
q5 = Sqrt[B^2 - (k0^2*e5*m5)];
wValues = Table[i, {i, Wi, Wf, Wstep}];
R1 = (1 - (((q1*m2*k0)/(q2*m1))*f))*Exp[-q2*d2];
R2 = (1 + (((q1*m2*k0)/(q2*m1))*f))*Exp[q2*d2];
R3 = (1 - (((q4*m5)/(q5*m4*k0))*j))*Exp[-q4*d4];
R4 = (1 + (((q4*m5)/(q5*m4*k0))*j))*Exp[q4*d4];
R = q3*wValues*10^(-9);
X = ((q2*m3)/(q3*m2))*((R2 - R1)/(R1 + R2));
Y = ((q4*m3)/(q3*m4))*((R3 + R4)/(R4 - R3));
disp = R - ArcTan[X] - ArcTan[Y] - m*Pi;
n = Table[j, {j, 1, nf, 1}];
BValues =
Table[FindRoot[disp[[n]], {B, 1.5578*10^7},
MaxIterations -> 10^5], {n, 1, nf, 1}]
BValues = Re[B /. BValues]
Nvalues = BValues/k0
I tried changing the starting value, but the error still appears. The values that I get from programme are complex. Is it necessary for the starting value that I choose be complex?
FindRoot[Evaluate@Expand[Times @@ (x - Range@20)], {x, 10}]
. (B) No, the result is wrong:FindRoot[(x - Sqrt[2.])^2 + 1., {x, 2}]
. -- Your description of the plot makes it sound as if (A) is more likely than (B), but the constant1.
in (B) can be made as small as1.*10^-7
. Can't say for sure whether your case is OK without the code. $\endgroup$dispn[B_] = disp[[n]];
throws an error but seems to be unused. Please reduce the code to a minimal working example. Also check whetherLength[disp]
andnf
match: something seems off. $\endgroup$