For context, I've already asked a question here about this same problem. I believe that my logic is now correct, even if I struggle to get the output in the format that I want. I would like to enter the initial conditions for this problem ($ x (0), dot {x} (0), y (0), dot {y} (0) $ and time information (initial time, end time, no time) and output a matrix containing the following values:

function (P) = ivpSolver (t0, dt, tends, x_0, xdot_0, y_0, ydot_0)

z (1,1) = x_0;

z (2.1) = xdot_0;

z (3.1) = y_0;

z (4.1) = ydot_0;

t (1) = t0;

n = 1;

while t (n) <= tends

t (n + 1) = t (n) + dt;

(z (1, n + 1); z (2, n + 1); z (3, n + 1);> z (4, n + 1)) = step RK4 (dt, z (1, n) z (2, n), z (3, n), z (4, n));

n = n + 1

end

function (znext) = stepRK4 (dt, z1, z2, z3, z4)

k1 = dt*stateDeriv (z1, z2, z3, z4);*

k2 = dtstateDeriv (z1 + k1 (1) / 2, z2 + k1 (2) / 2, z3 + k1 (3) / 2, z4 + k1 (4) / 2);

k3 = dt*stateDeriv (z1 + k2 (1) / 2, z2 + k2 (2) / 2, z3 + k2 (3) / 2, z4 + k2 (4) / 2);*

k4 = dtstateDeriv (z1 + k3 (1), z2 + k3 (2), z3 + k3 (3), z4 + k3 (4));

znext = (z1; z2; z3; z4) + (1/6) * (k1 + 2 * k2 + 2 * k3 + k4);

end

function (dz) = stateDevice (z1, z2, z3, z4)

H = 1500 * 10 ^ 3; % desired scientific orbit above the surface in m m = 2000; %

mass of the spacecraft in kg A = 12; % of the cross section of the spacecraft in

m Cd = 1.5; % drag coefficient of the spacecraft R = 2574.73 * 10 ^ 3; %

radius of the planet in m M = 1.3452 * 10 ^ 23; % mass of the planet in kg

G = 6.673 * 10 (- 11); % of the gravitational constant in Nm ^ 2kg ^ -2

r = sqrt (z1 ^ 2 + z3 ^ 2); % this is equivalent to sqrt (x ^ 2 + y ^ 2)

modv = sqrt (z2 ^ 2 + z4 ^ 2); % this is equivalent to sqrt (xdot ^ 2 + ydot ^ 2)

rho = profileTitan (r-R); % bring our rho value, taking into account

This is the area of grav = G*M / Rd (3/2); % c is the*

"magnitude" part of the friction part of the ODE

fric = (rhoCd * A) / (2 * m) * modv; % c is the "magnitude" part of the

severity part of the ODE

dz (1) = z2; % z1 = z2 dz (2) = – grav*Z1-money*z 2; % z2 = ODE part for x

dz (3) = z4; % z3 = z4 dz (4) = – grav*Z3-money*z4; % z4 = ODE part for there

end

My problem is that the function does not seem to like that I'm trying to get it out in a new column of the matrix. Any ideas how can I change that?