Message Boards Message Boards

0
|
6705 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Control the precision of the result with FindMinimum?

Posted 6 years ago

Dear all, I have an issue with a constrained minimization and FindMinimum.

Consider two cylinders of length L and radius R: the center of the first is located at the origin and its axis is parallel to the z axis, the center of the second is located at {xT, 0, xz}, and its axis is oriented according to the polar angles \theta and \phi.

Given two vectors {r[1],..,r[3]} and {s[1],..,s[3]}, I want to find the minimum of the square distance between them

f(r,s) = (r[1] - s[1])^2 + (r[2] - s[2])^2 + (r[3] - s[3])^2,

with the constraint that the vector {r[1],r[2],r[3]} lies within the first cylinder, and {s[1],..,s[3]} lies within the second cylinder:

In[1]:= R = 1/2;
L = 4;
xT = 78/100;
xz = -4/10;
\[CurlyTheta] = 8/10;
\[Phi] = 3;

In[7]:= FindMinimum[{(r[1] - s[1])^2 + (r[2] - s[2])^2 + (r[3] - 
     s[3])^2, r[1]^2 + r[2]^2 <= R^2, L + 2 r[3] >= 0, 
  2 r[3] <= 
   L, (Sin[\[Phi]] (xT - s[1]) + 
      Cos[\[Phi]] s[
        2])^2 + (Cos[\[CurlyTheta]] (Cos[\[Phi]] (-xT + s[1]) + 
         Sin[\[Phi]] s[2]) + Sin[\[CurlyTheta]] (xz - s[3]))^2 <= R^2,
   2 Cos[\[Phi]] Sin[\[CurlyTheta]] (xT - s[1]) + 
    2 Cos[\[CurlyTheta]] (xz - s[3]) <= 
   L + 2 Sin[\[CurlyTheta]] Sin[\[Phi]] s[2], 
  2 Sin[\[CurlyTheta]] Sin[\[Phi]] s[2] <= 
   L + 2 Cos[\[Phi]] Sin[\[CurlyTheta]] (xT - s[1]) + 
    2 Cos[\[CurlyTheta]] (xz - s[3])}, {{r[1], 0}, {s[1], xT}, {r[2], 
   0}, {s[2], 0}, {r[3], 0}, {s[3], xz}}]

Out[7]= {1.7518957310232823*10^-15, {r[1] -> 0.24200719173126448, 
  s[1] -> 0.24200723086912757, r[2] -> 0.0173827341902361, 
  s[2] -> 0.01738274867534208, r[3] -> -0.0952795259719789, 
  s[3] -> -0.0952795227618218}}

In this example the two cylinders overlap, the minimum is r = s, and the value of the objective function at the minimum must be zero. However, FindMinimum returns some small, but nonzero value ˜ 1e-15.

Is there a way to make sure that, if the minimum is x=y, then the minimum for the objective function is exactly zero, i.e., 0.?

Thank you.

POSTED BY: Joao Porto
4 Replies

This gives 0.:

FindMinimum[
 {(r[1] - s[1])^2 + (r[2] - s[2])^2 + (r[3] - s[3])^2,
  r[1]^2 + r[2]^2 <= R^2, L + 2 r[3] >= 0,
  2 r[3] <= L,
  (Sin[?] (xT - s[1]) + Cos[?] s[2])^2 + (Cos[?] (Cos[?] (-xT + s[1]) + 
          Sin[?] s[2]) + Sin[?] (xz - s[3]))^2 <= R^2,
  2 Cos[?] Sin[?] (xT - s[1]) + 2 Cos[?] (xz - s[3]) <=  L + 2 Sin[?] Sin[?] s[2],
  2 Sin[?] Sin[?] s[2] <= L + 2 Cos[?] Sin[?] (xT - s[1]) + 2 Cos[?] (xz - s[3])},
 {{r[1], 0}, {s[1], xT}, {r[2], 0}, {s[2], 0}, {r[3], 0}, {s[3], xz}},
 PrecisionGoal -> 100, AccuracyGoal -> 100]
(*
{0.`, {r[1] -> 0.10396492820425005`, s[1] -> 0.10396492820425005`, 
  r[2] -> 0.04034535330283793`, s[2] -> 0.04034535330283793`, 
  r[3] -> 0.15050819950441896`, s[3] -> 0.15050819950441896`}} 
*)

This gives an odd error (a bug?):

FindMinimum[
 {(r[1] - s[1])^2 + (r[2] - s[2])^2 + (r[3] - s[3])^2,
  r[1]^2 + r[2]^2 <= R^2, L + 2 r[3] >= 0,
  2 r[3] <= L,
  (Sin[?] (xT - s[1]) + Cos[?] s[2])^2 + (Cos[?] (Cos[?] (-xT + s[1]) + 
          Sin[?] s[2]) + Sin[?] (xz - s[3]))^2 <= R^2,
  2 Cos[?] Sin[?] (xT - s[1]) + 2 Cos[?] (xz - s[3]) <=  L + 2 Sin[?] Sin[?] s[2],
  2 Sin[?] Sin[?] s[2] <= L + 2 Cos[?] Sin[?] (xT - s[1]) + 2 Cos[?] (xz - s[3])},
 {{r[1], 0}, {s[1], xT}, {r[2], 0}, {s[2], 0}, {r[3], 0}, {s[3], xz}},
 PrecisionGoal -> 100, AccuracyGoal -> 100,
 WorkingPrecision -> $MachinePrecision]

LibraryFunction::cfsa: Argument 1.000000000000000157806333833570613362021`15.653559774527023*^-500 at position 3 should be a machine-size real number.

POSTED BY: Michael Rogers
Posted 6 years ago

My guess as to what to set WorkingPrecision was wrong. If you use WorkingPrecision -> 50 rather than WorkingPrecision -> 40, you'll get zero.

POSTED BY: Jim Baldwin
Posted 6 years ago

For specific issues you'll need to give specifics on f[x] and g[y]. But in the meantime you might want to increase WorkingPrecision to, say, 40 (something larger than the default value) and have and constants in f[x] and g[y] as rational numbers. And you might want to try Minimize rather than FindMinimum.

POSTED BY: Jim Baldwin
Posted 6 years ago

@ Jim Baldwin: Sure, I revised the question for clarity, and provided an explicit example. Note that in this example defining the constants as rational number does not solve the problem.

POSTED BY: Joao Porto
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract