# Optimize with constraints

I want to find the smallest $$k$$ such that $$kx^2 \ge (\sin(x)-x)^2$$ for all scalar $$x\in[a,\ b]$$? Obviously, I can do it analytically, but how can I do it (symbolically) in Mathematica? I am new to Mathematica and I am not really familiar with it.

• Have a look at Minimize: reference.wolfram.com/language/ref/Minimize.html
– Sâu
Oct 31, 2019 at 13:54
• I do not understand how to write "Minimize $k$ such that $g(k,x)\ge 0$ for all $x$ in the given range. How to set this constraint in Minimize? Oct 31, 2019 at 14:23

Edit: I think you need MinMax.

NMaximize[{(x^2 - 2 x Sin[x] + Sin[x]^2)/x^2, 4 <= x <= 5}, x]


{1.48166, {x -> 4.49341}}

So $$k=1.48166$$

RegionPlot[k x^2 >= (Sin[x] - x)^2, {x, -10, 10}, {k, -10, 10},
FrameLabel -> {"x", "k"}, Axes -> True,
GridLines -> {None, {1.48166}}, GridLinesStyle -> Red]


Your problem is equivalent to finding root of derivative of $$\frac{(\sin (x)-x)^2}{x^2}$$

  D[(Sin[x] - x)^2/x^2, x] // Simplify


$$\frac{2 (\sin (x)-x) (x \cos (x)-\sin (x))}{x^3}=0$$

Which is equivalent to

Solve[{Tan[x] - x == 0, 4 <= x <= 5}, x] // N


{{x -> 4.49341}}

RHS is positive and thus $$k\nless0$$. Therefore $$k=0$$ is the smallest value.

   RegionPlot[k x^2 >= (Sin[x] - x)^2, {x, -10, 10}, {k, -10, 10},
FrameLabel -> {"x", "k"}, Axes -> True]


Minimize[{1, k x^2 >= (Sin[x] - x)^2}, {k, x}]


{1, {k -> 0, x -> 0}}

Minimize[{1, k x^2 >= (Sin[x] - x)^2}, k]


$$\left\{ \begin{array}{cc} \{ & \begin{array}{cc} 1 & (\sin (x)=0\land x=0)\lor (\sin (x)=0\land x>0)\lor (\sin (x)=0\land x<0)\lor (\sin (x)>0\land x>0)\lor (\sin (x)>0\land x<0)\lor (\sin (x)<0\land x>0)\lor (\sin (x)<0\land x<0) \\ \infty & \text{True} \\ \end{array} \\ \end{array} ,\left\{k\to \begin{array}{cc} \{ & \begin{array}{cc} 2 & (\sin (x)=0\land x>0)\lor (\sin (x)=0\land x<0) \\ \frac{2 x^2-2 \sin (x) x+\sin ^2(x)}{x^2} & (\sin (x)>0\land x>0)\lor (\sin (x)>0\land x<0)\lor (\sin (x)<0\land x>0)\lor (\sin (x)<0\land x<0) \\ 0 & \sin (x)=0\land x=0 \\ \text{Indeterminate} & \text{True} \\ \end{array} \\ \end{array} \right\}\right\}$$

• The constraint should be satisfied for all $x$ in the interval, thus $k=0$ is obviously wrong. Oct 31, 2019 at 14:14
• Can you please provide such $x\in[a,b]$ so that $k=0$ is wrong? Oct 31, 2019 at 14:17
• Let $a=0$, $b=2$ and choose $x=1$. Then $kx^2=k$ and $(\sin(x)-x)^2 \approx 0.025$. The inequality $kx^2 \ge (\sin(x)-x)^2$ is not satisfied for $k<0.025$. Oct 31, 2019 at 14:21
• You minimized 1 rather than k. Minimize doesn't work with k; however, you can use NMinimize: NMinimize[{k, k x^2 >= (Sin[x] - x)^2}, {k, x}] Oct 31, 2019 at 14:29
• @BobHanlon How can I specify that the constraint should be satisfied only for the given range $x \in [a,\ b]$? Oct 31, 2019 at 14:32

Have a look at the expansion of Sin[x] around x=0. It starts with x. So the subtraction of x compensates for that. The idea with small x is apparently meant by the authors of this task. The second term in the expansion is since Sin is antisymmetric around x=0 x^3. So k is for some open surrounding of x=0 approximately the second order coefficient of the expansion of Sin around x=0.

So Sin[x] approx. x - x^3/3! + x^6/6! .+ ... . Convergence for the complete power series if infinity on the real numbers. So compare kx^2 with -x^3/6 which is always true for positive real numbers and limited for negative once since -x^3/6 gets positive.

The situation changes a bit for this task, because the cubic term is squared before comparison. Make yourself a different idea than that already given is the other discussions. Only the parabolas are a band with the linear occuring parameter k.

So draw (Sin[x] - x)^2 and kx^2 for k from 0 to 1 in steps of 0.05 or so and expand the interval around x=0 for increasing k. Both curves are symmetric for x=0. Some idea can be to replace k=l^2 and linearize the tasks. The monotonies of both side grant that there is a crossing. l(x)=(Sin[x]-x)/x=Sin[x]/x-1 approx. x^2/6 +O(x^5) still for small x.

• Thanks. However, as I told in the message, it is not a big deal to find the solution. However, I am more interested in how to do it Mathematica. Nov 1, 2019 at 10:48