Lecture7-8 - Interactive M-File An interactive M-file for...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Interactive M-File An interactive M-file for free-falling bungee jumper Use input and disp functions for input/output function velocity = freefallinteract % freefallinteract() % compute the free-fall velocity of a bungee jumper % input: interactive from command window % output: ve;ocity = downward velocity (m/s) g=9.81; % acceleration of gravity m = input( 'Mass (kg): ' ); cd = input( 'Drag coefficient (kg/m): ' ); t = input( 'Time (s): ' ); disp( ' ' ) disp( 'Velocity (m/s):' ) vel = sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t); disp([t;vel]’)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Interactive M-File- result >> freefallinteract Mass (kg): 68.1 Drag coefficient (kg/m): 0.25 Time (s): 0:1:20 Velocity (m/s): 0 0 1.0000 9.6939 2.0000 18.7292 3.0000 26.6148 4.0000 33.1118 5.0000 38.2154 6.0000 42.0762 7.0000 44.9145 8.0000 46.9575 9.0000 48.4058 10.0000 49.4214 11.0000 50.1282 12.0000 50.6175 13.0000 50.9550 14.0000 51.1871 15.0000 51.3466 16.0000 51.4560 17.0000 51.5310 18.0000 51.5823 19.0000 51.6175 20.0000 51.6416
Background image of page 2
Common Program Structures Sequence Selection Repetition
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Structured Programming Modular Design subdivides a system into smaller parts (modules) that can be independently created and then used in different. Subroutines (function M-files) called by a main program Top-Down Design Or "stepwise refinement". The software design technique which aims to describe functionality at a very high level, then partition it repeatedly into more detailed levels one level at a time until the detail is sufficient to allow coding. ( Originated at IBM; grew out of structured programming practices) Structured Programming design and coding of programs by top-down methodology that successively breaks problems into smaller, nested subunits. deals with how the actual code is developed so that it is easy to understand, correct, and modify
Background image of page 4
Structured Programming The ideal style of programming is Structured or Modular programming Break down a large goal into smaller tasks Develop a module for each task A module has a single entrance and exit Modules can be used repeatedly A subroutine (function M-file) may contain several modules Subroutines (Function M-files) called by a main program
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithm Design The sequence of logical steps required to perform a specific task (solve a problem) Each step must be deterministic The process must always end after a finite number of steps An algorithm cannot be open-ended The algorithm must be general enough to deal with any contingency
Background image of page 6
Structured Programming Sequential paths Sequence all instructions (statements) are executed sequentially from top to bottom * A strict sequence is highly limiting Non-sequential paths Decisions (Selection) – if, else, elseif Loops (Repetition) – for, while, break
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Selection (IF) Statements The most common form of selection structure is simple if statement The if statement will have a condition associated with it The condition is typically a logical
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 41

Lecture7-8 - Interactive M-File An interactive M-file for...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online