skydiver_if

# skydiver_if - % Verify that a filename was entered if...

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

Sheet1 Page 1 function [t, v] = skydiver_if % 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 am if statement for this example. response = input('Do you want to enter parameter values interactively? (y or n): ','s') if strcmp(response,'y') | strcmp(response,'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: ') elseif strcmp(response,'n') | strcmp(response,'N') % Read filename filename = input('Enter the name of the data file containing parameter values: ','s')

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

View Full Document
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) else % Bad input - return to Matlab command prompt fprintf('Illegal input - please rerun the program and enter y or n.\n') t = v = return end v = sqrt(m*g/c)*tanh(sqrt(g*c/m)*t) Sheet1 Page 2 % Determine if terminal velocity was reached % This is the most typical use of an if statement tol = 1e-4 npts = size(v,1) dv = abs(v(npts,1)-v(npts-1,1)) if dv &lt; tol disp('Terminal velocity was researched.') else disp('Terminal velocity was not reached.') end...
View Full Document

## skydiver_if - % Verify that a filename was entered if...

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

View Full Document
Ask a homework question - tutors are online