2
$\begingroup$

I've the following code:

R = 1;
L = 100;
c = 5;
\[Omega] = 1;
Uin = 1;
Plot[InverseLaplaceTransform[((Uin*\[Omega])/(s^2 + \
\[Omega]^2))*(R/(c*L*R*s^2 + L*s + R)), s, t], {t, 0, 
  10*((2 Pi)/\[Omega])}]

The output gives:

enter image description here

How can I find the global maximum of that function? So I need to find the time $t$ where the function on the y-axis is the biggest. I can see it is roundabout $t=17$ but how can I use Mathematica to solve for that point?

$\endgroup$
10
  • $\begingroup$ R = 1; L = 100; c = 5; \[Omega] = 1; Uin = 1; NMaximize[{ InverseLaplaceTransform[((Uin*\[Omega])/(s^2 + \[Omega]^2))*(R/(c*L* R*s^2 + L*s + R)), s, t], 10 < t < 20}, t] $\endgroup$ Commented Dec 19, 2019 at 12:39
  • $\begingroup$ @wuyudi I want to find a general solution, so I can not use the known values for $t$. In general do I not know the boundaries of $t$ $\endgroup$ Commented Dec 19, 2019 at 12:39
  • 1
    $\begingroup$ How about NMaximize[ InverseLaplaceTransform[((Uin*[Omega])/(s^2 + [Omega]^2))*(R/(cL Rs^2 + Ls + R)), s, t], t, Method -> "RandomSearch"] which produces $ \{0.0108751,\{t\to 17.0718\}\}$? $\endgroup$
    – user64494
    Commented Dec 19, 2019 at 13:08
  • $\begingroup$ @user64494 That does not always work. This gives a wrong answer: R = 10000; L = 340*10^(-3); c = 6*10^(-6); [Omega] = 2*Pif; f = 50; Uin = 33/10; NMaximize[{InverseLaplaceTransform[((Uin*[Omega])/(s^2 + \ [Omega]^2))*(R/(cLRs^2 + L*s + R)), s, t], t >= 0}, t, Method -> "RandomSearch"] $\endgroup$ Commented Dec 19, 2019 at 14:36
  • $\begingroup$ @user64494 Because it should find: $t\approx0.0248259$ $\endgroup$ Commented Dec 19, 2019 at 14:44

2 Answers 2

7
$\begingroup$
Clear["Global`*"]

R = 1;
L = 100;
c = 5;
ω = 1;
Uin = 1;

f[t_] = InverseLaplaceTransform[((Uin*ω)/(s^2 + ω^2))*(R/(c*L*R*
         s^2 + L*s + R)), s, t] // FullSimplify

(* (1/259001)(-100 Cos[t] - 499 Sin[t] + 
  5 E^(-t/10) (20 Cosh[t/(5 Sqrt[5])] + 509 Sqrt[5] Sinh[t/(5 Sqrt[5])])) *)

Plot the function to adaptively sample it

plt = Plot[f[t], {t, 0, 10*((2 Pi)/ω)}]

enter image description here

The points in the function are

data = Cases[plt, Line[pts_] :> pts, Infinity][[1]];

The peak data point is

peak = data[[SortBy[FindPeaks[data[[All, 2]]], Last][[-1, 1]]]]

(* {17.0672, 0.0108751} *)

Using this as an initial estimate, the function's maximum is then

FindMaximum[f[t], {t, peak[[1]]}, WorkingPrecision -> 20]

(* {0.010875072207704462201, {t -> 17.071813673825464498}} *)

or

Maximize[{f[t], 19/20 peak[[1]] < t < 21/20 peak[[1]]}, t, 
 WorkingPrecision -> 20]

(* {0.0108751, {t -> 17.0718}} *)
$\endgroup$
2
$\begingroup$

With additional information, that second derivative is negative (which NMaximize should know anyway), you get the right result.

Edit: I think, this works, because second derivative reproduces the Sin and Cos term with same but negative prefactor, so that NMaximize can eliminate these terms.

NMaximize[{f[t], D[f[t], {t, 2}] < 0}, t]

(*  {0.0108751, {t -> 17.0718}}    *)

Edit2

Even Maximizedoes the job easily if you restrict t a little bit away from zero.

Maximize[{f[t], 10^-6 < t < 100}, t, Reals]

You get a root expression for t which you can use for further analytical calculations.

{t -> Root[{-998 E^(1/50 (-5 + 2    Sqrt[5]) #1) + 
  501 Sqrt[5] E^(1/50 (-5 + 2 Sqrt[5]) #1) - 
  998 E^(-(1/50) (5 + 2 Sqrt[5]) #1) - 
  501 Sqrt[5] E^(-(1/50) (5 + 2 Sqrt[5]) #1) + 1996 Cos[#1] - 
  400 Sin[#1] &, 17.0718136738254647391}]}
$\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.