How to Output Updated Parameters Value in ode Integration Process When the odeEvent is triggered ?

I was working on multi-body systems collision simulation utilize ode MATLAB function and odeEvent function.
The impact between two body was built as a event using odeEvent MATLAB function.
The impact event will change some parameters which are incorporated in the governing equations of motion such as ydot=f(t,y,P).
I want to output the updated parameters when the impact event is triggered using fprintf function in the EventCallback function illustrated as follows :
function [stop,Ye,Pout] = impactEventCallback(te,ye,ie,Pin)
% ... parameters updating process
fprintf("The updated parameters are : %e", Pout)
end
However, when I simulate the impact process, there is no output display.
Can anyone give me some advices about how to output parameters when the impact event is triggered.

3 Comments

I test the impactEventCallback function with different parameters updating raw, nevertheless the simulation results do not change. I suspect that the impactEventCallback function does not be called although I have setted odeEvent object with following :
E = odeEvent("EventFcn",@(t,Y,P) impactEvent(t,Y,P),"Direction","ascending","CallbackFcn",@(te,Ye,ie,P) impactEventCallback(te,Ye,ie,P),"Response","proceed");
Hi Chuguang,
Did you try with the "Response" parameter set to "callback"?
@sai charan sampara thanks for your reply, I find that the issue is just as you said. I set the "Response" to "proceed". After I set it to "callback", it worked correctly!

Sign in to comment.

 Accepted Answer

Hi Chuguang,
The call back function is called whenever the event occurs, only if the "Response" parameter is set to "callback". If the "Response" parameter is set to "proceed" then the solver logs the event and continues integrating. So to resolve your issue change the "odeEvent" definition as follows:
E = odeEvent("EventFcn",@(t,Y,P) impactEvent(t,Y,P),"Direction","ascending","CallbackFcn",@(te,Ye,ie,P) impactEventCallback(te,Ye,ie,P),"Response","callback");

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Products

Release

R2024a

Asked:

on 27 Dec 2024

Answered:

on 27 Dec 2024

Community Treasure Hunt

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

Start Hunting!