Professional Documents
Culture Documents
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.
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.
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).
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).
= 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.