Homework #4

All problems MUST be in a SINGLE *.m file and be in separate blocks using '%% Problem X'. Otherwise you will not receive credit. You will need an additional file for the class definition. See class webpage for naming convention. NOTE: You need only submit one complete class definition file for all problems below.

Contents

Problem 1

Create a class called 'XX_ODESolver'. This class will numerically integrate an N-dimensional first-order ODE whose functional form is set by anonymous function (Similar to our 'NIntegrate' class) The functionality of the class will be demonstrated using the problems below. For Problem 1, Display the class definition in the command window using 'type'.

Problem 2

A certain radioactive element has a half-life of 1 month. Use the class and the Euler method to calculate what percentage is left after 1 year.

Problem 3

Implement a class method that plots the first dimension of the N-dimensional vector as a function of the integration variable (e.g. time). Use this to plot the percentage of remaining element as a function of time for up to 1 year.

Problem 4

A mass of 1 kg is attached to a spring that has spring constant 10 N/m. At time t=0, the mass is let go from 1 m above it's equilibrium position. Use Euler's Method and a dt=.001 s to find and plot the position over time for 100 s. Plot the analytical solution on the same plot using a different color.

Problem 5

Repeat Problem 4 using the 4th order Runge-Kutte method.

Problem 6

Create a movie that shows the position, velocity and net force of/on the mass as a function of time. The movie must play in real-time.