1
$\begingroup$

I have function defined in such way:

ω0=145199+1;       
f=1;
b=ω0/4;
s[ω_] := NDSolve[{x''[t]+b x'[t]+ω0^2 x[t]==f Sin[ω t],x[0]==0,x'[0]==0},x[t],{t,0,2π/ω0}];
x[t_,ω_]:=s[ω][[1,1,2]];

I'm trying to find t and ω for which the max. of the function occurs.

ωmax = NMaximize[{x[t,omg], 0<=t<=2π/ω0},{t, omg}]

Overall I am trying to find resonant frequency for which the largest oscillation occurs. Unfortunately I get this error: error

I have searched the reference, the stack and could not find the answer for the problem.

$\endgroup$
2
  • $\begingroup$ Can you include the definition of f, b (make sure the example you show is complete) $\endgroup$ – Szabolcs Mar 23 '20 at 15:46
  • $\begingroup$ That's right, sorry. $\endgroup$ – Pekureda Mar 23 '20 at 15:47
2
$\begingroup$
Clear["Global`*"]

ω0 = 145199 + 1;
f = 1;
b = ω0/4;

The differential equation can be solved exactly

x[t_, ω_] = DSolveValue[
   {x''[t] + b x'[t] + ω0^2 x[t] == f Sin[ω t],
    x[0] == 0, x'[0] == 0}, x[t], t] //
  FullSimplify[#, 0 <= t <= 2 π/ω0] &

enter image description here

EDIT: Use of arbitrary precision is necessary. This is done by specifying a WorkingPrecision for NMaximize

ωmax = 
 NMaximize[{x[t, ω], 0 <= t <= 2 π/ω0, 
    0 < ω < 2 ω0}, {t, ω}, 
   WorkingPrecision -> 50] // N

(* {7.09473*10^-11, {t -> 0.0000274786, ω -> 84877.3}} *)

Show[
 Plot3D[x[t, ω], {t, 0, 2 π/ω0}, {ω, 0, 2 ω0},
  AxesLabel -> Automatic,
  ClippingStyle -> None],
 Graphics3D[{Red, AbsolutePointSize[5], 
   Point[{t, ω, x[t, ω]} /. ωmax[[2]]]}]]

ed

$\endgroup$
3
  • $\begingroup$ Awesome! This value should be calculated as a product of "numerical experiment", whatever it means. It looks like I have to watch some tutorials of using mathematica to know how does it actually works. Unfortunately I have all lectures cancelled because of ncov and we were made to do something here, without any preparation etc. so I am kind of lost. Anyway thanks and I wish you good health! $\endgroup$ – Pekureda Mar 23 '20 at 16:39
  • $\begingroup$ @Pekureda - Note that I had to further increase the precision to get a correct value. $\endgroup$ – Bob Hanlon Mar 23 '20 at 16:42
  • $\begingroup$ Yeah. Although it is not in the problem described here, I was able to get some values out of it, but only when ω was treated as constant, so I hoped I would get the answer. $\endgroup$ – Pekureda Mar 23 '20 at 16:46

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.