
valg=2;
h=0.001;
x=0:h:1;
y=zeros(length(x),1);
y(1)=1;

%eksplisitt euler
if valg==1
    for i = 1:length(x)-1
        y(i+1)=y(i)+h*x(i)*y(i)^2;
    end
end

%RK4
if valg==2
    for i = 1:length(x)-1
        k_1=x(i)*y(i)^2;
        k_2=(x(i)+h/2)*(y(i)+h/2*k_1)^2;
        k_3=(x(i)+h/2)*(y(i)+h/2*k_2)^2;
        k_4=(x(i)+h)*(y(i)+h*k_3)^2;
        y(i+1)=y(i)+h/6*(k_1+2*k_2+2*k_3+k_4);
    end
end

disp(y(end)-2)
    
