Reputation: 11
I have a multi-dimensional surface whose equation is y=a1x1^2 + b1x1 + a2x2^2 + b2x2 + ... + anxn^2 + bnxn + c.
Now, I need to get the point on this surface closet to the given point.
I hope my wording of my problem hasn't confused you guys too much and thank you in advance.
Look forward to the reply.
Upvotes: 1
Views: 90
Reputation: 3957
Try a 2 dimensional and 3 dimensional example to show one way of doing this in Mathematica.
p = {7, 2};
f = {x1, 2 x1^2 + 3 x1};
sol = NMinimize[Norm[p - f], Most[f], Method->"RandomSearch"][[2]];
q = f /. sol;
Print[q];
Show[Graphics[Line[{q, p}]], Plot[Last[f], {x1, -1, 1}]]
p = {7, 3, 2};
f = {x1, x2, 2 x1^2 + 3 x1 + x2^2 - 4 x2};
sol = NMinimize[Norm[p - f], Most[f], Method->"RandomSearch"][[2]];
q = f /. sol;
Print[q];
Show[Graphics3D[Line[{q, p}]], Plot3D[Last[f], {x1, -2, 2}, {x2, 0, 7}]]
Generalize to n dimensions.
Upvotes: 1