MATLAB: How i change/update a part of the equation (a constant that changes each iteration, for example) during the integration with ode function

differentialequationintegrationodeode45recalculate

Hello.
Well as the title said, i have a group of differential equations integrating with the ode 45 function, in other hand i have a separate group of simple equations that gives a determined force that enters in one of the differential equations as a constant.
I want to obtain this value of force based in a initial value then integrate the equations, after this i want to update the force values based in the past values and integrate again and so on until the integration time comes to and end.
Example of the code:
[t,X]=ode45(@test,0:0.01:20,[0, 0]);
...
function dx=test(t,x)
m=1;
r=1;
c=1;
kv=1
K=10;
Da=10;
el=2;
S=2;
s0=0;
e=2;
e0=0;
D=Da+K;
O=-eL*D;
S=S0+D*(e-e0)+O*K;
e=S/D;
Force=S;
dx=zeros(2,1);
dx(1)=x(2);
dx(2)=(-c*x(2)-kv*x(1)-Force+m*r*(cos(x(3))-((x(4))^2)*sin(x(3))));
%%% I Want to update in every step the S and e constants of the equations like this: S0=S; e0=e; and recalculate the Force every step.

Best Answer

How are you updating ‘S’ and ‘e’? I don’t see them changing.
If you want to make a parameter a function of time, that is easily enough done. See: Problem with ode45 for a way to produce time-dependent parameters.
Also, ‘dx(3)’ is always going to be zero.