%% Example 4.5
% Amplification Factor

%% 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))

%% 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')