1
$\begingroup$

I have the following problem (in Mathematica) I want to calculate the following expressions:

Assuming[{t > 0, t \[Element] Integers}, 
 Minimize[Sqrt[(Sin[t*Pi/6] - x)^2 + (Pi/6 - x)^2], x]]

How can I get a unique result?

The other question: what is if my function has 2 parameters, like t and s which do not get any numerical values however restrict to be from N (Integer). What is the key name, may I say "multivariate minimisation"?

Thanks

$\endgroup$
5
  • 1
    $\begingroup$ FullSimplify[Minimize[f[x], x], Assumptions -> t > 0]? $\endgroup$ Mar 17 '16 at 18:21
  • $\begingroup$ Your minimization is over $x$. The value of your function depends, of course upon $t$. For different $t$s, you get different minima. $\endgroup$ Mar 17 '16 at 18:27
  • $\begingroup$ @DavidG.Stork, you are write but what is your suggestion something like: Minimize[f[t*x], {x,t}] ? $\endgroup$
    – maniA
    Mar 17 '16 at 18:32
  • $\begingroup$ @Dr.belisarius: wau thanks it works but why? and what about if I have t and s in another combination? $\endgroup$
    – maniA
    Mar 17 '16 at 18:37
  • $\begingroup$ In[1582]:= NMinimize[{Sqrt[(Sin[t*Pi/6] - x)^2 + (Pi/6 - x)^2], Element[t, Integers]}, {x, t}] Out[1582]= {0.0166868542533, {x -> 0.511799387799, t -> 1}} $\endgroup$ Mar 17 '16 at 18:38
1
$\begingroup$

I suggest removing the Sqrt. Here the minima are derived in different ways:

f[u_, x_, t_] := u[(Sin[t*Pi/6] - x)^2 + (Pi/6 - x)^2]
p1 = Plot[Evaluate[f[Identity, x, #] & /@ Range[-5, 5]], {x, -4, 4}];
exp = x /. First@Solve[D[f[Identity, x, t], x] == 0, x];
pts = Table[{exp, f[Identity, exp, t]} /. t -> j, {j, -5, 5}];
p2 = ListPlot[List /@ pts, PlotMarkers -> {Automatic, 20}];
min = Minimize[f[Identity, x, t], x];
gm = t /. Last@Minimize[min[[1]], t];
cv = (x /. min[[2]]) /. t -> gm;
pi = Show[p1, p2, 
   Graphics[{Text[Style["x", 20], {cv, f[Identity, cv, gm]}]}], 
   PlotRange -> {{-1, 1}, {0, 5}}, ImageSize -> 300];
pc = Plot[Evaluate[f[Sqrt, x, #] & /@ Range[-5, 5]], {x, -4, 4}, 
   Epilog -> {PointSize[0.03], Point[{cv, f[Sqrt, cv, gm]}]}, 
   ImageSize -> 300];
Row[{pi, pc}]
Row[{"t=", gm, ", x=", cv}]

The family of curves is shown for illustration. The minimum of family of curves is black cross in no sqrt and black point in sqrt plot. The values of t and xare shown below.

enter image description here

$\endgroup$
0
$\begingroup$

Apparently, there is no analytic solution, so just use numerical minimization over your two variables:

NMinimize[{Sqrt[(Sin[t π/6] - x)^2 + (π/6 - x)^2], 
  t > 0, 
  t \[Element] Integers}, 
  {x, t}]

$\{0.0166869,\{x\to 0.511799,t\to 1\}\}$

And try this, to visualize:

Plot[
 Evaluate@
  Table[Sqrt[(Sin[t*Pi/6] - x)^2 + (Pi/6 - x)^2], {t, 7}], {x, 0, 1},
 PlotStyle -> Table[Hue[i]/10, {i, 7}],
 PlotLegends -> Automatic]

If your question is instead: "Given a $t \in \mathbb{Z}^+$, find the $x$ that minimizes the function", then:

Minimize[Sqrt[(Sin[t π/6] - x)^2 + (π/6 - x)^2], x]

An even better way is to find the value of $x$ (as a function of $t$) for the problem without the square root (avoiding multiple roots), then substituting the found $x$ into your full function:

Sqrt[(Sin[t π/6] - x)^2 + (π/6 - x)^2] /.
 Minimize[(Sin[t π/6] - x)^2 + (π/6 - x)^2, x][[2]]

$\sqrt{\left(\frac{1}{12} \left(-6 \sin \left(\frac{\pi t}{6}\right)-\pi \right)+\frac{\pi }{6}\right)^2+\left(\frac{1}{12} \left(-6 \sin \left(\frac{\pi t}{6}\right)-\pi \right)+\sin \left(\frac{\pi t}{6}\right)\right)^2}$

$\endgroup$
2
  • $\begingroup$ Thanks a lot David, but I am interested in a x so that for all t >0 the function is minimised. in a mathematical way x_min \[Element] [a,b] for every t and I am interested in inf of this set $\endgroup$
    – maniA
    Mar 17 '16 at 18:44
  • $\begingroup$ There is no way to find a single $x$ such that your function is minimized for all $t$. $\endgroup$ Mar 17 '16 at 18:45

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.