0
$\begingroup$

With the function $f(x) = x^3 - 12 x + 2$. To find the least value of the function $f(x)$ with $-2\leqslant x \leqslant 2$, I tried

Minimize[{f[x], -2 <= x <= 2}, x]

{-14, {x -> 2}}

I am trying to find the least value of the function $(f(x+m))^2$, I tried

Clear["Global`*"]
f[x_] = x^3 - 12  x + 2;
g[x_] = f[x + m]^2;
Minimize[{g[x], -2 <= x <= 2}, x]

I don't get the Out of Mathematica. How can I find the least value of a function with parameter $(f(x+m))^2$?

$\endgroup$
2
  • $\begingroup$ What do you mean you "don't get the Out of Mathematica"? In v14.1, I get a result without any issues ... $\endgroup$
    – Domen
    Commented Oct 24 at 15:10
  • 1
    $\begingroup$ The answer is not a number, if that's whet you were expecting. $\endgroup$
    – rhermans
    Commented Oct 24 at 15:34

2 Answers 2

4
$\begingroup$
$Version

(* "14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024)" *)

Clear["Global`*"]

f[x_] = x^3 - 12 x + 2;

Since g is a function of two variables, there should be two arguments.

g[m_, x_] = f[x + m]^2;

If all you need to know is the minimum value, use MinValue rather than Minimize. This will give a leaner result.

min[m_] = MinValue[{g[m, x], -2 <= x <= 2}, x]

enter image description here

To convert the Root expressions to radicals use ToRadicals

min2[m_] = min[m] /. r_Root :> ToRadicals[r]

enter image description here

Graphically,

Plot[min[m], {m, -564/100, 549/100},
 PlotPoints -> 150,
 MaxRecursion -> 5,
 WorkingPrecision -> 15,
 ImageSize -> Large,
 Epilog -> Inset[LogPlot[min[m], {m, -20, 20}],
   {2.75, 5}]]

enter image description here

$\endgroup$
0
$\begingroup$
Clear["Global`*"]
f[x_] = x^3 - 12    x + 2;
g[m_, x_] = f[x + m]^2;
minimizeForEachm[m_] := Minimize[{g[m, x], -2 <= x <= 2}, {x}]
dataPoints = 
  ParallelTable[
   Module[{ele = minimizeForEachm[m]}, {m, x /. Part[ele, 2], 
     Part[ele, 1]}], {m, Range[-20, 20, 0.001]}];
ListPointPlot3D[dataPoints, 
 AxesLabel -> {"parameter m", "optimal x", "MinValue"}, 
 PlotRange -> Full]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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