I am trying to solve an ode in a loop, trying to get a single vx and tx value as ouput. I wish to use a loop because a parameter is to be changed everytime a new loop starts. I am getting length 0 output after calling the ode45 function. I wish to integrate the ODE over just one time interval that I have specifed (t(i:i+1)) to get a single value ouput in tx and vx Can you explain how to rectify the issue?
t = linspace(1,10);vf(1) = 30 ; %some random constant value
vfx = vf(1); % needed in the function ode_research_x
x(1) = -3;% starting point for x
for i = 1:length(t)-1 vfx = vf(1); % this vfx is then used by the ode_research_x function
[tx,vx] = ode45('ode_research_x', t(i:i+1), vp(1)); % I am not sure but the time step seems like an issue
x(i+1) = x(i) + vx.*tx; vp(1) = vx; vf(1) = 30; % some new constant value calculated in the loop (I've shown a random value)
end%function to define the ode
function dudt = ode_research_x(vx,vfx)dudt = 18*mu_f*Cd*Rep*(vx - vfx)/(rho_p*d^2*24); % all the variables except vx and vfx are constant values in the same workspace so I haven't shown their values but they are defined
end
Best Answer