function v = skydiver_func6 % Function to calculate skydiver falling speed % for specified parameter values and time vector % using the analytic solution. % % Inputs: mass m (kg) % gravity g (m/s^2) % drag coefficient c (kg/m) % time vector (s) % % Outputs: falling speed vector v (m/s) % Read inputs from a data file called data.txt data = load('data.txt'); nrows = size(data,1); m = data(1,1) g = data(2,1) c = data(3,1) t = data(4:nrows,1) v = sqrt(m*g/c)*tanh(sqrt(g*c/m)*t); % Save time and calculated speed vectors to a text file save speeds1.txt t v -ascii -double -tabs % data in one long column outputs = [t v]; save speeds2.txt outputs -ascii -double -tabs % Save time and calculated speed vectors to a text file % as two formatted columns fid = fopen('speeds3.txt','w'); fprintf(fid,' Time Speed\n'); fprintf(fid,' %3.1f %5.2f\n', t, v); fclose(fid);