skydiver_switch - Verify that a filename was entered if...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 function [t, v] = skydiver_switch % Function to calculate skydiver falling speed with % input method selected on the fly. % % Inputs: mass m (kg) % gravity g (m/s^2) % drag coefficient c (kg/m) % time vector (s) % % Outputs: falling speed vector v (m/s) % Check if user wants to input parameter values interactively. % If not, assume the user will input parameter values from a file. % Use a switch statement for this example. response = input('Do you want to enter parameter values interactively? (y or n): ','s') switch response % Note: I could use lower(response) to make response lower case case {'y','Y'} % Read parameter value inputs m = input('Enter mass in kg: ') g = input('Enter gravity in m/s^2: ') c = input('Enter drag coefficient in kg/m: ') t = input('Enter time vector in s: ') case {'n','N'} % Read filename filename = input('Enter the name of the data file containing parameter values: ','s')
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % Verify that a filename was entered if isempty(filename) fprintf('No file name entered - aborting program.\n') return end data = load(filename) nrows = size(data,1) m = data(1,1) g = data(2,1) c = data(3,1) t = data(4:nrows,1) otherwise % Bad input - return to Matlab command prompt fprintf('Illegal input - please rerun the program and enter y or n.\n') t = v = return end Sheet1 Page 2 v = sqrt(m*g/c)*tanh(sqrt(g*c/m)*t) % Determine if terminal velocity was reached tol = 1e-4 npts = size(v,1) dv = abs(v(npts,1)-v(npts-1,1)) % How can we use a switch statement to print out the correct message? % We need to turn dv into either a string or an integer. if dv < tol message = 1 else message = 2 end switch message case 1 disp('Terminal velocity was researched.') case 2 disp('Terminal velocity was not reached.') end...
View Full Document

This note was uploaded on 09/05/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 2

skydiver_switch - Verify that a filename was entered if...

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

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