1
$\begingroup$

How can I find the maximum value (and the corresponding $x$) of the following function with parameter $t$: $$ f(x) = |x^2-tx + 2t|$$

on a closed interval $x\in[0,1]$?

I tried using Maximize, but it doesn't give a result:

f[x_] := Abs[x^2 - t x + 2 t]
Maximize[{f[x], 0 <= x <= 1}, x]
(* Maximize[{Abs[2 t - t x + x^2], 0 <= x <= 1}, x] *)
$\endgroup$
2
  • $\begingroup$ how about {t->-(3/2)} ? $\endgroup$
    – Nasser
    Commented Aug 15, 2023 at 9:54
  • $\begingroup$ @Nasser t==3/2||t==-3/2 $\endgroup$
    – csn899
    Commented Aug 15, 2023 at 10:07

3 Answers 3

3
$\begingroup$
Indicating that `t` is real, one succeeds

Solve[Maximize[{RealAbs[2 t - t*x + x^2], 
 0 <= x <= 1 && t >= -Infinity}, x][[1]] == 3]

{{t -> -(3/2)}, {t -> 3/2}}

$\endgroup$
3
  • 1
    $\begingroup$ If I change the t to look like thist \[Element] Reals why can't I find the value? $\endgroup$
    – csn899
    Commented Aug 15, 2023 at 10:45
  • $\begingroup$ @csn899: Sorry, don't understand. Please, present the whole code. $\endgroup$
    – user64494
    Commented Aug 15, 2023 at 10:58
  • 1
    $\begingroup$ I got your remark: Solve[Maximize[{RealAbs[2 t - t*x + x^2], 0 <= x <= 1 && t \[Element] Reals}, x][[1]] == 3, t] produces "Solve::nsmet: This system cannot be solved with the methods available to Solve". Don't know the reason. $\endgroup$
    – user64494
    Commented Aug 15, 2023 at 11:05
5
$\begingroup$

Abs is a Complex Function. We use Sqrt[x^2] instead.

sol = Maximize[{Sqrt[(x^2 - t*x + 2 t)^2], 0 <= x <= 1}, x]
Plot[{sol[[1]], x /. sol[[2]]}, {t, -5, 5}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Sqrt[(x^2 - t*x + 2 t)^2] is nothing, but RealAbs[x^2 - t*x + 2 t]. FullSimplify[Sqrt[(x^2 - t*x + 2 t)^2] - RealAbs[x^2 - t*x + 2 t]] results in 0. $\endgroup$
    – user64494
    Commented Aug 15, 2023 at 11:10
4
$\begingroup$

Numerical approach

max[t_?NumericQ] := {t, x /. #[[2]], #[[1]]} &[ NMaximize[{ Abs[x^2 - t x + 2 t], 0 <= x <= 1}, x]]

ParametricPlot[{max[t][[{1, 2}]], max[t][[{1, 3}]]}, {t, -3, 3},PlotLegends -> {"x[t]", "max[t]"}]

t-dependent maximal value max[t] is always at x==0or x==1!

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.