Writing a new answer so that I can use markup (MathWorks, please fix this!!). You need a couple of things - first, the time values
You can now work out how many steps you need:
Now, we need an array in which to store your results: each column should correspond to a value from your t vector
We know the initial condition, so we'll pop that in
Now we need a loop to store the subsequent x values. The basic structure will look like this
for i = 2:n
k1 = h*f(x(:, i-1));
k2 = ...
k3 = ...
k4 = ...
x(:, i) = x(:, i-1) + ...
end
plot(t, x)
And that should pretty much be all you need
Best Answer