I want to solve a nonlinear equation eq
in a Manipulate
environment as the following one using a Locator
Manipulate[
eq = {u1*Cos[u2], u1*Sin[u2]};
cond = 0 <= u1 <= 10 && 0 <= u2 < 2 Pi;
nsol = NSolve[{p == eq, cond}, {u1, u2}, Reals] // Quiet;
Grid[{
{Graphics[{Point[p]}, PlotRange -> 5, Axes -> True]}
, {nsol}
}]
, {{p, {1, 1}}, Locator}
]
I am aware that the nonlinear equation is the transformation into cylindrical coordinates, and I know how to get these analytically. But this is just a simple example, later I want to solve other more complex equations with other conditions. I am interested in computing the solution smoothly while dragging the locator across the plot.
My problems are
- the performance is poor (I suppose I have to use
Dynamic
sowhere but I dont know where and more importantly why). How do I have to program this correctly in order to have a smooth computation while dragging the locator in the graphic? - I have to tell
NSolve
to beQuiet
, otherwise I get the warning, that the system can not be solved but with inexact coefficients (which is fine for me). Is there any other way to do this already inNSolve
?
EDIT: computation and usage of results of NSolve
@Kuba: thank you for the information, I will read through everything you posted. I have a further question (which I was not able to solve with the first version of your answer), but if this is answered in the references you gave, then just say it and I will find my way there.
Sorry for expanding the question, but my first formulation was not precise. I would also want to use the results of NSolve
for other purposes within Manipulate
, e.g., computing a field with the results and drawing an arrow as follows
Manipulate[
eq = {u1*Cos[u2], u1*Sin[u2]};
cond = 0 <= u1 <= 10 && 0 <= u2 < 2 Pi;
nsol = NSolve[{p == eq, cond}, {u1, u2}, Reals] // Quiet;
field = {u1 + Cos[u2^2], -Sin[u2]};
Grid[{
{Graphics[{Point[p], Arrow[{p, p + field /. nsol[[1]]}]},
PlotRange -> 5, Axes -> True]}
, {nsol}
, {field /. nsol[[1]]}
}
, Alignment -> Left
]
, {{p, {1, 1}}, Locator}
]