# 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 '19 at 5:59

If you are looking for real solutions {k,\[Omega]} ContourPlot shows possible solution pairs

Clear[k]
ContourPlot[finalrelation == 0, {k, 200, 300}, {\[Omega], 0, 1000},MaxRecursion -> 4, FrameLabel -> {k, \[Omega]}]


If you are interested on real solutions for given k==300 you have to tell Solve the range of \[Omega]:

Solve[{finalrelation == 0 /. k -> 300,0 < \[Omega] < 10000}, \[Omega], Reals]
(* {{\[Omega] -> 0.254258}, {\[Omega] -> 0.499999}, {\[Omega] ->480.344}, {\[Omega] -> 587.544}, {\[Omega] ->3105.54}, {\[Omega] -> 3966.27}} *)

• Wwll, we can give the range only when we know prior what the answers will be. I just do not want to use it. – sreeraj t May 21 '19 at 8:34
• @ sreeraj t: No, depending on the physical problem you usualy know some details of the solution, for example {Element[{\[Omega], k}, Reals], {\[Omega] > 0, k > 0} }. I can't understand why the restriction of the solution range of \[Omega] should be a problem. – Ulrich Neumann May 21 '19 at 8:54
• many thank you for that comment. But sorry to tell you that I cannot agree with you as in my case, I cannot give any range of solution that I anticipate. – sreeraj t May 22 '19 at 1:06