% Neil Edelman (110121860)
function f = sincosde(a, b, res, f0)
% solves df/dt = sin(cos(f(t))), f(a) = f0 over the range a:res:b

dn = (b - a) / res;
% preallocate the solution matrix and a variable matrix
f(res + 1) = 0;
x = [a:dn:b];

% fill it in
f(1) = f0;
n = a + dn;
for i = 1:res
    k1 = dn * sin(cos(x(i)));
    k2 = dn * sin(cos(x(i) + k1 / 2));
    k3 = dn * sin(cos(x(i) + k2 / 2));
    k4 = dn * sin(cos(x(i) + k3));
    f(i + 1) = f(i) + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
    n = n + dn;
end
figure(1);
plot(x, f);
title 'dx/dt = Sin(Cos(x(t)))';
xlabel 't';
ylabel 'x(t)';
