How write an event function using a 6x1 state vector.
Show older comments
Hello, I am trying to write an event function where my state vector, Y, is a 6x1 vector made up of position and velocity
Y = [r; v] = [r1; r2; r3; v1; v2; v3]
r and v are 3x1 vectors as seen above.
I would like to have my ODE45 simulation stop when norm(r) <= (a certain scalar magnitude), but I am unsure how to do this with the event function.
Answers (1)
Walter Roberson
on 28 Apr 2023
function [value,isterminal,direction] = myEventsFcn(t,Y)
value = SCALAR - norm(Y(1:3));
isterminal = 1;
direction = 0;
end
This codes to stop when SCALAR - norm(Y(1:3)) is positive (actually, when it crosses 0). constant minus function is positive when function becomes less than the constant.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!