skydiver_while2

# skydiver_while2 - break end end % Compare with analytic...

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

Sheet1 Page 1 function [t, v] = skydiver_while2(m,g,c,dt,tol) % 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 % calculate the correct terminal speed. % % Inputs: mass m (kg) % gravity g (m/s^2) % drag coefficient c (kg/m) % time increment (s) % convergence tolerance tol (m/s) % 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 1 % Increment counter i = i+1 % Update v vold = vnew dvdt = g-(c/m)*vold^2 vnew = vold + dvdt*dt % Update t told = tnew tnew = told + dt % Update tol tolnew = abs(vold-vnew) % Store new solution t(i,1) = tnew v(i,1) = vnew if tolnew < tol

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: break end end % Compare with analytic solution to see how good our final value % 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 Sheet1 Page 2 % accuracy of the numerical solution. vtrue = sqrt(m*g/c)*tanh(sqrt(g*c/m)*t(i,1)) 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_while2 - break end end % Compare with analytic...

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

View Full Document
Ask a homework question - tutors are online