Updating States in ODE45
Show older comments
Hi everyone!
I modeled a free falling sphere in air with ODE45 as coded below, and it hits the ground. I wanted to update position and velocity of sphere as it hits the ground and bounce back to air again each time as it hits the ground. I coded the main function in a main file and modeled the equation of motion in a seperate file with a function named "Equation_of_Motion".
Can someone hlep me how I can update the position and velocity of the sphere with odeset and event function in MATLAB as the sphere reaches to ground and hits it each time? It would be great if you could hlep to how I can use events functions in the link I mentioned as below:
Thanks,
The main function code is as below:
clear all;clc;close all;
%% Static paramters
ball_radius = 0.15; % radius of the balls
%% Dynamic parameters
g=9.81; % gravity
COR=0.5;
Mass=1;
Force_Free_Falling=Mass*g;
v0_x=0;
v0_y=0;
v0_z=0;% initial velocity
z0=3;% initial position of center of cube in space
FinalTime=1.5;% Time priod
tolerance=0; % in what tolerance we would start the collision integration
%% Equation of Motion
[t,x] = ode45(@(tt,xx) Equation_of_Motion(tt, xx,Mass,Force_Free_Falling), [0, FinalTime], [z0, v0_z]);
z_Position=x(:,1);
z_Velocity=x(:,2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
and the equation of motion file named "Equation_of_Motion" is as below as well:
function xdot = Equation_of_Motion(t,x,Mass,Force_Free_Falling)
pos = x(1);
vel = x(2);
xdot = zeros(2,1);
xdot(1) = vel;
xdot(2) = -Force_Free_Falling/Mass;
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations 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!