How write an event function using a 6x1 state vector.

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.

回答(1 个)

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.

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by