ODE45Example

# ODE45Example - y0 = 10 yp0 = 0 Define initial state vector...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 function ODE45Example % Function to demonstrate how ODE45 works using a dropped ball bouncing % on a plane. % Assume that contact between the ball and the ground is modeled as a % nonlinear spring F = k*y^1.5, which is like a Hertzian contact model. % Make y = 0 be ground level, and make the state vector x = [y yp]'. global k m g % Define system parameter values k = 1e6 m = 10 g = 9.8 dt = 0.01 tf = 10 % Calculate time points based on specified value of dt tspan = 0:dt:tf % Specify initial conditions

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y0 = 10 yp0 = 0 % Define initial state vector x0 = zeros(2,1) x0(1,1) = y0 x0(2,1) = yp0 % Perform numerical integration with ODE45 [t,x] = ode45(@BallContact,tspan,x0) y = x(:,1) plot(t,y,'LineWidth',2) %-------------------------------------------------------------------------function dx = BallContact(t,x) global k m g y = x(1,1) yp = x(2,1) if y < 0 F = k*(abs(y))^1.5-m*g else F = -m*g end ypp = F/m dx(1,1) = yp dx(2,1) = ypp Sheet1 Page 2...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

ODE45Example - y0 = 10 yp0 = 0 Define initial state vector...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online