# Numerical method for harmonic oscillator with jumping constant

Let $$k_1 \neq k_2$$ be positive reals, $$t_0 > 0$$ and consider the following Cauchy problem in $$[0,+\infty)$$: $$\begin{cases} y(t) + k(t)y''(t) = 0 \newline y(0) = 1/\sqrt{k_1} \newline y'(0) = 0, \end{cases}$$ where $$\begin{equation} k(t) = \begin{cases} k_1 \hspace{1 cm} 0 \leq t \leq t_0 \newline k_2 \hspace{1 cm} t > t_0 \end{cases} \end{equation}$$

It is clear that there exists a unique $$C^1$$ solution $$y$$ in $$[0,+\infty)$$, obtained by gluing two smooth solutions of the equation in $$[0,t_0]$$ and $$[t_0,+\infty)$$. An explicit computation gives: $$\begin{equation} y(t) = \begin{cases} \dfrac{1}{\sqrt{k_1}} \mathrm{cos} \bigg(\dfrac{t}{\sqrt{k_1}} \bigg) \hspace{1 cm} 0 \leq t \leq t_0; \newline A \ \mathrm{cos}\bigg( \dfrac{t}{\sqrt{k_2}} + \phi \bigg) \hspace{1 cm} t > t_0, \end{cases} \end{equation}$$ where $$A$$ and $$\phi$$ are obtained imposing the $$C^1$$ condition. With further computations one discovers that the amplitude is constant, i.e. $$A = 1/\sqrt{k_1}$$, if and only if $$t_0 = n \pi \sqrt{k_1}$$ for some $$n \in \mathbb N$$.

I am searching for a good numerical method for the problem in the constant-amplitude case. I have tried several classical schemes, but I discovered that when $$k_2 >> k_1$$ the second amplitude also grows bigger. Any suggestion?

• Try a symplectic integrator from DifferentialEquations.jl in Julia: docs.sciml.ai/dev then use events to handle the jump. You can also specify that you want to integration steps to include $t_0$ so you hit the jump dead-on Apr 24 '20 at 3:29
• @whpowell96 thank you, I'll have a look. Apr 24 '20 at 6:22
• @ChrisRackauckas Apr 24 '20 at 18:06
{"ft_lang_label":"__label__en","ft_lang_prob":0.58105063,"math_prob":0.9999721,"size":1258,"snap":"2021-43-2021-49","text_gpt3_token_len":470,"char_repetition_ratio":0.11881977,"word_repetition_ratio":0.021390375,"special_character_ratio":0.36168522,"punctuation_ratio":0.08906882,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999975,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-08T09:54:55Z\",\"WARC-Record-ID\":\"<urn:uuid:19dc9726-5cbe-4720-b2ea-9e37bb9c1345>\",\"Content-Length\":\"129139\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:c4c6bcda-6a98-471f-8ced-eb1ae415a7b8>\",\"WARC-Concurrent-To\":\"<urn:uuid:1b31a957-3451-4687-9bee-8b13eecf2a05>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://scicomp.stackexchange.com/questions/34922/numerical-method-for-harmonic-oscillator-with-jumping-constant\",\"WARC-Payload-Digest\":\"sha1:HPBR2HF7X2YHKLSNWERKGX6YNNRWTKTC\",\"WARC-Block-Digest\":\"sha1:AQNRJJGDLGWLUW6PPWUNXWGPWFTVARJC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964363465.47_warc_CC-MAIN-20211208083545-20211208113545-00508.warc.gz\"}"}