Example 4.5
Amplification Factor
Contents
Setup
close all; clear g t yee yrk ytrue amp_true amp_ee amp_rk i; g = @(t,y)sqrt(-1)*y;
Generate Solutions
[t,yee] = explicit_euler(g,[0 20],1,100); [t,yrk] = rk2(g,[0 20],1,100); ytrue = exp(i*t);
Amplification
amp_true = max(abs(ytrue)) amp_ee = max(abs(yee)) amp_rk = max(abs(yrk))
amp_true = 1 amp_ee = 7.106683346278307 amp_rk = 1.020197260317442
Plot
figure(1) plot(t,real(yee)) hold on plot(t,real(yrk),'r') plot(t,real(ytrue),'g') grid on xlabel('t') ylabel('y') legend('Euler','RK2','True','Location','NorthWest')
![](ch4ex5_01.png)