FF505 – Computational Science
Week 6, Spring 2016 [pdf format]

MATLAB Exercises

Work in small groups at the computer to solve the following exercises.

  1. Read chapter 9 from the course reference [SW] and finish the exercise from the previous week on population dynamics.
  2. Create a new function in a file named addme.m that accepts one or two inputs and computes the sum of the number with itself or the sum of the two numbers. The function must be then able to return one or two outputs (a result and its absolute value). [Hint: you may need the system variable nargin]
  3. Curve fitting. Read chapter 12 from the course reference [SW]. Then generate 10 points in the Cartesian plane and fitt a polynomial of order three on those points. Compare the quality of two alternative solution one via ployfit and another via fminsearch. Finally plot the points and the fitted curve.
  4. Projectile trajectory. From classical physics we know that the position vector p of a projectile in the 3D space is described as follows:
     ptp0utsmt+
    g t2
    2
    where sm is the muzzle velocity (speed at which the projectile left the weapon), ut is the direction the weapon was fired, and gy=−9.81 ms−1 is the gravity.