2
$\begingroup$

So I have a nice code that runs properly, which I include below but, in my naiveté, I'm having issues iterating my procedure.

Simply put, I have a function of two real variables $f(x,y)$ and I want to manually parameterize part of its zero set. It has to be manually, because the cases I'm ultimately interested in have many complicated components, of which I only want one specific one.

So I input a point $P_{0}$ which I know on the zero set. I then produce a unit tangent vector to the zero set at $P_{0}$, pick a tiny step-size $h$, multiply this unit vector by $h$ and use a minimization procedure to find a nearby point $P_{1}$ on the curve. I would like to iterate this procedure to get two vectors of the same size: $\{0,h,2h,3h,\ldots \}$ and the corresponding $(x,y)$ values on the curve corresponding to that parameter value. Here is my code so far:

f[x_, y_] = (x^2 + y^2 - 4)*((x - 1)^2 + y^2 - 4);
Dell[a_, b_] = Grad[f[a, b], {a, b}];
V[a_, b_] = (1/Norm[Dell[a, b]])*{Dell[a, b][[2]], -Dell[a, b][[1]]};
P0 = {2, 0};
h = 0.05;
Dis[x_, y_] = Norm[P0 + h*V[P0[[1]], P0[[2]]] - {x, y}];
N[Minimize[{Dis[x, y], f[x, y] == 0}, {x, y}], 10][[2]]

That last line of the code successfully outputs a nearby point on the curve $P_{1}$ which I would now like to use as input to carry out this recipe again, and get the two lists/vectors described above. Can someone perhaps help me with this step? Much appreciated.

$\endgroup$
2
$\begingroup$

You can use NestList to apply your function multiple times, but we need to modify your function for that purpose.

As a first step, since we are not interested in the value of your function at the minimum, but only in the values of its arguments there, I am going to use NArgMin instead of your N@Minimize combination. We also need to redefine the Dis function to accept the value of the previous point as input.

The following uses your previous definitions for all functions and arguments, except Dis, which is redefined as shown below:

Clear[Dis]
Dis[p_] := Norm[p + h*V[Sequence @@ p] - {x, y}]

NestList[
  NArgMin[{Dis[#], f[x, y] == 0}, {x, y}] &,
  P0, 4
]

(* Out: {{2, 0}, {2.9975, 0.0999225}, {2.99938, 0.0499693}, {3., -0.0000150731}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.