You are on page 1of 4

PHYS205 Matlab Laboratory 2

Adrian McDonald
The tasks below are intended to test your ability to write simple Matlab
code. You should label the m-files you create Task1.m etc as you will need to
submit this code for marking next week.

NOTE: You should add comments to document the various steps in your
scripts and functions.

Task 1: Make a program that simulates radioactive decay.


The ordinary differential equation for determining the rate of radioactive
decay can be written as:

where is the decay constant which can be related to the half life, t, of the
material by:
1 =
2

(2)

Write a script that calculates the change in the number of uranium 238 atoms
over a 10,000 million year period using Eulers method. You may assume there
are 10,000 uranium 238 atoms initially and the half life of uranium is 3050
million years. Use a step size of 10 million years in your calculation.

Task 2: Impact of step size


Using your script from Task 1 as a starting point. Make a piece of code that
calculates the number of uranium 238 atoms that have not decayed after 1000
million years for step sizes of 10, 50, 300 to 1000 million years. Plot all of the
resultant curves on the same diagram

Task 3: Write a function that calculates the fourth order Runge-Kutta


equations for any specified function
Use the midpoint algorithm function in the lecture notes as the basis for
writing a fourth order Runge-Kutta algorithm which works for any function
specified.

Task 4: Solve the damped SHM ODE.


Use the function you created in Task 3 to solve the ODE below that represents
a damped oscillator (as shown in the Figure on the next page):

2
2

+ = 0

You will want to create a function damped oscillator to perform this action.
Use values of the mas of 3 kg, a value for the damping factor 10.0 and a spring
constant of 300 N/m in your main script which calls your Runge-Kutta
algorithm. Select TWO appropriate initial conditions for this system and an
appropriate value of the time step (trial and error will work).

Task 5: Motion in free-fall including air resistance


Use the Matlab ode45 solver to solve the ODE below that represents an object
in free fall, but which also includes air resistance in the equation of motion:
2
2

You will want to create a function motion in free fall to perform this task. Use
values of the gravitational acceleration of 9.81m/s2 and a value for the air drag
parameter of 0.2. Select TWO appropriate initial conditions for this system and
an appropriate value of the time step (trial and error will work). Then plot how
the speed of the object varies as a function of time from zero to 5 seconds.

Task 6: Motion in free fall for a range of values of the air drag parameter

Use the code created for Task 5 as a template to make a contour diagram of
the velocity of the object as a function of time (from 0 to 5.0 seconds) for
values of the air drag parameter between 0 and 1.0 (in increments of 0.05).

Task7: Projectile motion with air drag


The ODEs for projectile motion can be written as:

= 2 + 2

= 2 + 2 -g
=
=

Use the ode45 solver to derive trajectories for the case of a specified air drag
(k=0.2) associated with a particle launched from the origin. You should be able
to input any speed and angle from the horizontal for the initial condition. The
script should use the output from the solver to plot the trajectory on a graph.
You should run the solver for a large enough period so that the projectile
reaches the ground (x=0) again, then remove all values of positions where x is
less than 0 (use the find command to do this) and set these values to Not a
Number (NaN see Matlab help) to ensure you make a nice graphic like the one
shown below.

You might also like