Hello. I am running ode45 to simulate the dynamics of a nonlinear system. Inside the dynamics function that ode45 calls, I have an if statement that sets two of the state variables (thetadot and thetaddot) to 0 if a certain condition is met. However, when ode45 calls the dynamics function again on the next time step, thetadot is NOT equal to zero. Why is the value of thetadot changing from one time step to the next?
Here is my call to ode45:
[t,y] = ode45(@(Tspan, y0) singleDynamicsCoil(Tspan,y0,mu0,coils,mag,...
mass,w,L,h,ct,cn,Bmax), Tspan, y0, options) ;
And here is the if statement that sets thetadot and thetaddot to 0:
if abs(Bangle - theta) < 1E-1
disp('***ACTIVATING TH = 0 CONDITION***') ;
Th = 0 ;
Tb = 0 ;
thetadot = 0 ;
thetaddot = 0 ;
thetaddot = (1/I) * (Tb - Th) ;
qdot = [xdot ; ydot ; thetadot ; xddot ; yddot ; thetaddot] ;
I have a display statement at the top of the dynamics function here:
function qdot = singleDynamicsCoil(t,q,mu0,coils,mag,mass,w,L,h,ct,cn,Bmax)
x = q(1) ;
y = q(2) ;
theta = q(3) ;
xdot = q(4) ;
ydot = q(5) ;
thetadot = q(6) ;
The last line, disp(thetadot) is the line that reveals that even though I set thetadot = 0 at the end of the dynamics function in the last time step, its value has been changed to some non-zero value before the next call to the dynamics function. Why is this happening?
Thank you in advance for your time and help.