skydiver_error - for i = 1:4 % Determine time vector and...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 function skydiver_error(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)*10) % 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
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: for i = 1:4 % Determine time vector and number of points t = [0:dt(i,1):10]' 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 and approximate percent errors et(i,1) = abs((vapprox(i,1)-vtrue)/vtrue)*100 if i == 1 ea(i,1) = NaN else Sheet1 Page 2 ea(i,1) = abs((vapprox(i-1,1)-vapprox(i,1))/vapprox(i,1))*100 end end % Output results in a formatted table vtrue = vtrue*ones(4,1) outputs = [dt vtrue vapprox et ea] fprintf('\n dt vtrue vapprox et ea\n') fprintf('%4.2f\t %5.2f\t %5.2f\t %5.3f\t %5.3f\n', outputs') fprintf('\n')...
View Full Document

Page1 / 2

skydiver_error - for i = 1:4 % Determine time vector and...

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