# Euler's Method using Matlab

1. Nov 6, 2011

### TriclesCr

1. The problem statement, all variables and given/known data

Question :

The ball is kicked at a 5m high vertical wall 20m away. The initial speed of the ball is Vm/s and its initial angle of motion is C degrees with the horizontal (both the speed and angle are inputs). When the ball strikes the wall it bounces back with coefficient of restitution e , eventually returning to ground between the wall and the kicker.

The forces acting on the ball are gravity and a wind that acts at right angles to the initial motion of the ball, which generates a force of WN
The ball has diameter of 1 metre and weighs 0.5 kg.
Using Euler’s method,determine the location where the ball strikes the ground.

2. The attempt at a solution

I've never used matlab before,so i was looking for a tutorial about euler's method on matlab and i found this one : http://www.me.ucsb.edu/~moehlis/APC591/tutorials/tutorial1/node4.html

So i came up with this :

First i divided my work into 2 phases,first phase is when the ball hits the wall,the second one is when the ball bounces back and hit the ground.

%input
m = 0.5; %weighs
g = 9.81; % gravity
w = 1.06; %Wind Force
h = 0.5; %timestep
e = 0.78; % coefficient of restitution
npoints = 41;
%since my stationary point is at the centre of the ball so the distance between the Stationary point to the wall is now 20.5m(41xtimestep(0.5)=20.5)

V = input('Initial Speed ');
C = input('Initial Angle ');
V;
C;

%Equation for the first phase (when ball hits the wall)
% Centre of the ball as a stationary point
% y''(doubledot)=-g
% x''(doubledot)=0
% z''(doubledot)=w/m

%reduce to first oder equations
% let m = y' , s = x' , r = z'

x =zeros(npoints,1);%this initialize the vector y to being all zeros
y =zeros(npoints,1);
z =zeros(npoints,1);
m =zeros(npoints,1);
s =zeros(npoints,1);
r =zeros(npoints,1);

%Initial Condition
x(1) = 0;
y(1) = 0;
z(1) = 0;
m(1) = V*sind(C); %ydot(0)
s(1) = V*cosd(C); %xdot(0)
r(1) = 0; %zdot(0)

for n=1:npoints-1 %loop over the timesteps

m(n+1) = m(n) + h*-g;
y(n+1) = y(n) + h*m(n);

s(n+1) = s(n) + h*0;
X(n+1) = x(n) + h*S(n);

r(n+1) = r(n) + h*(w/m);
z(n+1) = z(n) + h*r(n);

end

plot(x,y,z);

==================================================
is that code right ?
I have not tested yet because i dont have matlab on my laptop,i did that one notepad.
If that is right,
How do i calculate the new velocity of the ball when it bounces back using e (coefficient of restitution ) ?
Once I get the new velocity,do I need to do the same step as above with different initial condition ?

Thanks
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution