Matematik och Datavetenskap, Chalmers Tekniska Högskola och Göteborgs Universitet
u''(t)+u(t)=0, a<t<b,
u(a)=u0, u'(a)=u1
by first writing it as a system of two first order equations:
w'=Aw, a<t<b,
w(a)=wa
where w=[u; u'], wa=[u0; u1], A=[0 1; -1 0].
Remember that the algorithm is
t0=a
W(t0)=wa
ti=ti-1+h
W(ti)=W(ti-1)
+ h AW(ti-1)
Use the template my_trig.m. Use a rather large step in the beginning (h=1e-1), so that you can easily see if t and W come out right. (Type t and W after running the program, to see the computed values.)
3. Run the program with initial value w0=[0; 1]. Plot the solution in two ways
figure(1)
plot(t,W) % solution curves
figure(2)
plot(W(:,1),W(:,2)) % phase portrait
axis equal
Which function do you get? Experiment! Do both sin and cos. Can you see that they are periodic? What is the period?
3. Modify the program so that it solves
u''(t)+c2u(t)=0, a<t<b,
u(a)=u0, u'(a)=u1
where c is a constant. Show that the solution formula is (with a=0)
u(t)= u0 cos(ct) + (u1/c) sin(ct).
Hint: compute the derivative u'' and check that the equation and the initial condition are satisfied.
Now take c=2, u0=0, u1=1. Plot the solutions as before. Explain the difference. Hint: we have
4w12+w22=1.
(Prove this!) What geometric figure is this?
4. Modify the program so that it computes sinh(t) and cosh(t) instead. Hint: replace c2 by -1 in 3. Plot the solutions.
/stig