{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

skydiver_error2

# skydiver_error2 - for i = 1:4 Determine time vector and...

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

Sheet1 Page 1 function skydiver_error2(m,g,c) % Function to calculate true and approximate percent % error for skydiver falling speed at t = 10 sec using % four different time increments % % Inputs: mass m (kg) % gravity g (m/s^2) % drag coefficient c (kg/m) % time increment dt (s) % All inputs are passed into the function. % % Outputs: final falling speed v (m/s) % true percent error et (%) % approximate percent error ea (%) % Assign 4 dt values dt = [2 1 0.5 0.25]' % Allocate memory for approximate solutions vapprox = zeros(4,1) % Calculate analytical solution at t = 10 sec vtrue = sqrt(m*g/c)*tanh(sqrt(g*c/m)*dt) % Allocate memory for true and approximate percent errors et = zeros(4,1) ea = zeros(4,1) % Loop through dt values and calculate the true percent % and approximate percent error in each case

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: for i = 1:4 % Determine time vector and number of points t = [0:dt(i,1):dt(i,1)]' npts = size(t,1) v = 0 % Use Euler's method to generate approximate solution for j = 1:npts-1 % Update v dvdt = g-(c/m)*v^2 v = v + dvdt*dt(i,1) end % Save approximate solution vapprox(i,1) = v % Calculate true percent errors % Note that we don't want to calculate approximate percent errors here % since when we halve the step size, we are estimating v at a new % point et(i,1) = abs((vapprox(i,1)-vtrue(i,1))/vtrue(i,1))*100 Sheet1 Page 2 end % Output results in a formatted table %vtrue = vtrue*ones(4,1) outputs = [dt vtrue vapprox et] fprintf('\n dt vtrue vapprox et\n') fprintf('%4.2f\t %5.2f\t %5.2f\t %5.2f\n', outputs') fprintf('\n')...
View Full Document

{[ snackBarMessage ]}