You have a couple of problems with your code. Your ode_research does not follow the ordinary form (dydy = ode_f(t,y)) that ode45 expects. Then your use of a string for the first argument is a bit arcane. I would expect something like this would be better:
t = linspace(1,10);
vf(1) = 30 ;
vfx = vf(1);
x(1) = -3;
vp = v_initial;
for i = 1:length(t)-1
vfx = vf(1);
[tx,vx] = ode45(@(t,vx) ode_research_x(t,vx,vfx), t(i:i+1), vp(1));
x(i+1) = x(i) + vx(end).*tx;
vp(1) = vx;
vf(1) = 30;
end
function dudt = ode_research_x(t,vx,vfx)
dudt = 18*mu_f*Cd*Rep*(vx - vfx)/(rho_p*d^2*24);
end
This looks like some attemt to integrate an equation of motion, if that is the case this is not a good way to go about it. In that case you should integrate the second-order ODE (i.e. the two coupled first order-ODEs) and handle the evolution of the force inside the ode_research_x - function.
HTH
Best Answer