150 likes | 366 Views
Program Design Using MATLAB Lecture 3: Supporting Material Dr Kathryn Merrick Tuesday 10 th March, 2009. Overview. From problem to program Defining a function Comments and code structure. An Introductory Problem…. Physics of a Stoppie.
E N D
Program Design Using MATLAB Lecture 3: Supporting Material Dr Kathryn Merrick Tuesday 10th March, 2009
Overview • From problem to program • Defining a function • Comments and code structure
Physics of a Stoppie Source: Bicycle and Motorcycle Dynamics http://en.wikipedia.org/wiki/Bicycle_and_motorcycle_dynamics
From Problem to Program… • Understand the problem ‘in English’ • Develop a rough solution on paper • Implement the solution in MATLAB • Test your solution
Example: A Stoppie Calculator • The problem ‘in English’: I’d like to write a program that can tell me if a particular bike can do a stoppie. • The rough solution: I’m going to write some code that can automatically compute the normal force on the rear wheel given the wheelbase and centre of mass height. Harley-Davidson FXD Honda VFR800
Demo 1: Stoppie Calculator in MATLAB
Pros and Cons of the Stoppie Calculator • Advantages: • Computation is done automatically • Disadvantages: • I have to manually enter the variable values every time • I have to write in the equation every time • There must be a better way….!
Demo 2: A Better Stoppie Simulator
Summary • After today’s lecture you should be able to: • Take a problem ‘in English’ and develop a rough solution • Use the MATLAB command line to implement a solution • Define simple functions as reusable solutions