%Lab 3
%Written by Jeannette Spuhler, 2011-11-15

%Numerisk derivering
%Differentialekvationssystem


clear all; clc;
tslut = 1;
h=0.2;%steglängd
%begynnelsevärde
t=0;
y=[100 0 0]';
T = t;
Y=y';
n = tslut./h; %antal tidsteg

%stegar framåt med RK4
for i= 1:n 
    f1=fsonderfall(t,y);
    f2= fsonderfall(t+h/2, y+h*f1/2); 
    f3= fsonderfall(t+h/2, y+h*f2/2);
    f4= fsonderfall(t+h, y+f3); 
    y=y+(h/6)*(f1+2*f2+2*f3+f4); 
    t=t+h;
    T = [T; t];
    Y = [Y; y'];
end
plot(T, Y(:, 1), T, Y(:, 2), T, Y(:, 3)); 
legend('A', 'B', 'C');
xlabel('t');
ylabel('Sönderfall');
title('Lab3 - Differentialekvationssystem'); 