skydiver_params

# skydiver_params - % Store new solution t(i,1) = tnew v(i,1)...

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

Sheet1 Page 1 function [t, v] = skydiver_params(f,dt,tol,varargin) % Function to calculate skydiver falling speed % for specified parameter values and time increment % using an iterative, numerical solution with % a while loop. For this problem, the goal is to show % how varargin can be used to pass input parameters to % the function passed into this function. % % Inputs: Function handle to first derivative function % time increment (s) % convergence tolerance tol (m/s) % varargin % which should be % mass m (kg) % gravity g (m/s^2) % drag coefficient c (kg/m) % if we pass in derivparams as the function to be called. % % All inputs are passed into the function. % % Outputs: falling speed vector v (m/s) % Iterate the solution until the final velocity stops changing tolnew = 1 tnew = 0 t(1,1) = 0 vnew = 0 v(1,1) = vnew i = 1 while tolnew > tol % Increment counter i = i+1 % Update v vold = vnew dvdt = f(vold,varargin{:}) vnew = vold + dvdt*dt % Update t told = tnew tnew = told + dt % Update tol tolnew = abs(vold-vnew)

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

View Full Document

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: % Store new solution t(i,1) = tnew v(i,1) = vnew end % Compare with analytic solution to see how good our final value Sheet1 Page 2 % of v is. Note that we cannot normally do this, but we will do it % here to develop an understanding of what factors influence the % accuracy of the numerical solution. % vtrue = sqrt(m*g/c)*tanh(sqrt(g*c/m)*t(i,1)) % Note that we can no longer do the line above since m, g, and c % are no longer known to the program. fprintf('The numerical final velocity is %7.4f m/s.\n', v(i,1)) % fprintf('and the analytical final velocity is %7.4f m/s.\n', vtrue) fprintf('The final time is %7.4f sec.\n', t(i,1)) % Question: How accurately can we find the time required to reach % terminal velocity? Only to within dt of the true value. Sheet1 Page 3 % Why do we need this statement? % Can/should I pre-allocate memory for v? % Why is this line needed? % Why not abs((vold-vnew)/vnew)? Sheet1 Page 4...
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 / 4

skydiver_params - % Store new solution t(i,1) = tnew v(i,1)...

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

View Full Document
Ask a homework question - tutors are online