summaryrefslogtreecommitdiff
path: root/coursework17/RK4second.m
blob: 7388c2715bb691e23c2adc5e98afaf5ec88aa4f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
function [x, y] = RK4second(t,x,y,h,g,f)
k1x = h*g(t, x,y);
k1y = h*f(t, x,y);
k2x = h*g(t+h/3, x+k1x/3, y+k1y/3);%if it doesnt work try k1y after y
k2y = h*f(t+h/3, x+k1x/3, y+k1y/3);
k3x = h*g(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
k3y = h*f(t+2*h/3, x-k1x/3+k2x, y-k1y/3+k2y);
k4x = h*g(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
k4y = h*f(t+h, x+k1x-k2x+k3x, y+k1y-k2y+k3y);
x = x+(1/8)*(k1x+3*k2x+3*k3x+k4x);
y = y+(1/8)*(k1y+3*k2y+3*k3y+k4y);
end