# Discrepancy in the solution provided by NSolve

I have a code which goes like this:

First one

ClearAll["Global*"]

θ = 80 Degree;(*angle*)

firstterm = 1 + 20/(32 k^2);

secondterm = (
20000 ((ω - 5 k)^2 - 1900^2))/((ω -
5 k)^4 - ((ω - 5 k)*1800)^2 - (60*
k^2 ((ω - 5 k)^2 - 1700^2)));

thirdterm = (
22000*(ω^2 - 0.5^2))/(ω^4 - ω^2 - (3*
k^2*(ω^2 - 0.5^2)));

fourthterm = (150000*(ω^2 -
0.35^2))/(ω^4 - (0.5 ω)^2 - (1.5 k^2 (ω^2 - (0.08)^2)));

finalrelation = firstterm - secondterm - thirdterm - fourthterm;

roots = ω /. NSolve[finalrelation == 0, ω];

kstart = 1;
kdivision = kstart;
kend = 300;

data = Table[Flatten@{k/760., roots/70000},
{k, kstart, kend, kdivision}] ;

SetDirectory[NotebookDirectory[]];

data1 = Join[{{"k", "RR1", "RR2", "RR3", "RR4", "RR5", "RR6", "RR7",
"RR8", "RR9", "RR10", "RR11", "RR12"}}, data];

Export["dat-file-for-theta=" <> ToString[θ] <> ".dat", data1, "Table"];

Second one

ClearAll["Global*"]

θ = 80 Degree;(*angle*)

k = 300;

firstterm = 1 + 20/(32 k^2);

secondterm = (
20000 ((ω - 5 k)^2 - 1900^2))/((ω -
5 k)^4 - ((ω - 5 k)*1800)^2 - (60*
k^2 ((ω - 5 k)^2 - 1700^2)));

thirdterm = (
22000*(ω^2 - 0.5^2))/(ω^4 - ω^2 - (3*
k^2*(ω^2 - 0.5^2)));

fourthterm = (150000*(ω^2 -
0.35^2))/(ω^4 - (0.5 ω)^2 - (1.5 k^2 (ω^2 - (0.08)^2)));

finalrelation = firstterm - secondterm - thirdterm - fourthterm;

a = Table[Flatten@{300/
760., (ω /. NSolve[finalrelation == 0, ω])/70000}]

If you run the portion titles "First one", Mathematica solves the equation and export to a .dat file. If you look at the roots given, except for the last value of k, it can be seen that for single value of k, it has 12 roots and which is written onto .dat file, which is correct. But for the last value of k, it is showing that it has 22 roots for single value of k.

If you run the section "Second one" which solves exclusively for last k, only 12 roots can be seen. So the roots given for the last value of k in "First one" is wrong.

Unlike getting a duplicate solution as discussed here, I am getting a complex number. When running the "First one", I am getting 0.05666103182587515-0.013814997186653053, but second one gives me no roots like this- though it gives me 0.056661031825875154.

What is happening here? From where does this extra roots come? Where are am I making mistake?

• I get 12 values in every row, including the last one. – MelaGo May 21 at 5:59