# N inside Manipulate: evaluating and showing roots of quartic in real time

Consider the parameterized quartic

ClearAll[p];
p[m_, n_] :=
Function[{x}, -7 - m - n +
m n + (-7 m - 8 n + 3 m n) x + (10 - 5 m - 8 n + m n) x^2 + (6 -
m - 2 n) x^3 + x^4 // Evaluate]


We are interested in the sum and product of roots for $$m,n>4$$. So this helps visualize the problem...

DynamicModule[
{pt = {4, 4}, m, n},
m = Dynamic[pt[[1]]];
n = Dynamic[pt[[1]]];

r = x /. NSolve[p[m, n][x] == 0, x];(*..............1*)
s1 = r[[1]] + r[[2]];
s2 = r[[3]] + r[[4]];
p1 = r[[1]] r[[2]];
p2 = r[[3]] r[[4]];
(*{s1}*)                             (*..............2*)

{
Graphics[Locator[Dynamic[pt]], PlotRange -> {{4, 10}, {4, 10}},
Axes -> True],
{N[s1, 5]}

(*Column[{
{m,n},
{s1,s2,p1,p2}
(*N/@{s1+s2,p1+p2+s1 s2,s1 p2+s2 p1,p1 p2}*)

}]*)
}
]



However as seen in this picture, the sum of roots isn't simplified to a single number but suspended to an expression with radicals.

Why does N not work here? (I did try the solver part-lines marked 1 to 2- outside Manipulate and it works as expected showing just a single evaluated number)

You must use "Manipulate" and leave out the superfluous (in "Manipulate") "Dynamic". Here is the corrected code:

ClearAll[p];
p[m_, n_] :=
Function[{x}, -7 - m - n +
m n + (-7 m - 8 n + 3 m n) x + (10 - 5 m - 8 n + m n) x^2 + (6 -
m - 2 n) x^3 + x^4 // Evaluate]

Manipulate[
m = pt[[1]];
n = pt[[1]];
r = x /. NSolve[p[m, n][x] == 0, x];
s1 = r[[1]] + r[[2]] // N;
s2 = r[[3]] + r[[4]];
p1 = r[[1]] r[[2]];
p2 = r[[3]] r[[4]];
{Graphics[Locator[Dynamic[pt]], PlotRange -> {{4, 10}, {4, 10}},
Axes -> True], s1}
, {{pt, {4, 4}}, Locator}
]

• thnx..works..though can you please explain the meaning of passing Locator in Manipulate's range spec Feb 9, 2021 at 14:43
• This is not a range spec but the controller type. Feb 9, 2021 at 14:45