I have the following code to execute:
$X$ = [0;0;0;0]; $sw$ = 0;
for k = 1 : n
if (sw(k) == 0 && X(2,k)> 0.7 ) || (sw(k) == 1 && X(1,k) >0)
sw(k+1) = 1;
X(:,k+1) = X(:,k) +h*(A1*X(:,k) + B1*u);
else
sw(k+1) =0;
X(:,k+1) = X(:,k) +h*(A*X(:,k) + B*u);
end
end
This is fine. I wanted to solve the same ODE using the bulit-in ode suite. How do I check for $sw$ and $X$ after each iteration to see which one of the two equations to solve.
odeset
documentation in Matlab (especially aboutEvents
). But be aware that pure "how do I use this function in Matlab" questions are off-topic here, and better asked at Matlab Answers. (Your question is borderline, depending on how you edit it.) $\endgroup$