Programming in MATLAB
Engineering Programs
honors engr161 HW #11 code
This program will calculate the max distance of a crate pushed by a man, given that the mass is 60 kg, distance before man falls is 8 m, the angle of the ramp is 30 degrees, and gravity is 9.81 m/s. The program will utilize the plot function in order to plot 2 lines for the max distance that the crate moves versus the constant force that the man exerts with different coefficients of restitution.
% Homework #11 MATLAB % File: HW_11_liu2102.m % Date: 17 November 2017 % By: Erica Liu % liu2102 % Section: 2 % Team: 35 % % ELECTRONIC SIGNATURE % Erica Liu % % The electronic signature above indicates that the program % submitted for evaluation is my individual work. I have % a general understanding of all aspects of its development % and execution. % % This program will calculate the max distance of a crate pushed by % a man, given that the mass is 60 kg, distance before man falls is 8 m, % the angle of the ramp is 30 degrees, and gravity is 9.81 m/s. The % program will plot 2 lines for the max distance that the crate moves % versus the constant force that the man exerts with different coefficients % of restitution. The program will calculate this % with different amounts of force in which a for loop will account for. clc clear %set the different forces force = 480:600; i = 1; % loop that calculates the distance with different amounts of force, % one line per coefficient of restitution for f = force A(i) = distance(f , 0.36); B(i) = distance(f, 0.42); i = i + 1; end %make the graphs f1 = figure; plot(force,A,'b',force,B,'r'); title('Max Distance vs Force Exerted'); xlabel('Force Exerted'); ylabel('Max Distance'); legend('u = 0.36','u = 0.42'); %user-defined function: calculate velocity, used from homework problem #5 function velocity = finalVel(force, coeff) rightSide = (force * 8) - (coeff * 60 * 9.81 * 8 * cos(30 / 180 * pi)); pe = 9.81 * 60 * 8 * sin(30 / 180 * pi); variable = rightSide - pe; ke = 30; velocity = sqrt(variable / ke); end %user-defined function: calculate distance, used from homework problem #5 function totDist = distance(force, coeff) pe = 294.3; friction = coeff * 60 * 9.81 * cos(30 / 180 * pi); changeDist = (30 * (finalVel(force, coeff))^2) / (friction + pe); totDist = 8 + changeDist; end
honors engr162 HW #11
This problem asked to calculate factorial values using both Stirling's Formula and the factorial function itself. The calculations were then graphed and used for comparison, as shown below.
% Graph the approximated and actual factorial scatter plots figure pointsize = 20; h1 = scatter(integers, approximated, 'r'); hold on h2 = scatter(integers, actual, 'b'); hold off xlabel('Integer'); ylabel('Approximated/True Value'); legend([h1, h2], {'Approximation', 'Factorial'}) % Graph the percent error scatter plot figure h3 = scatter(integers, error, 'g'); xlabel('Integer'); ylabel('Percent Error'); legend(h3, 'Percent Error');
HW #8 Code
This problem asked to predict the amount of dissolved oxygen in the Wabash River using a given formula. It will indicate whether the concentration is between a certain range using an asterisk (*).
% Homework #8 MATLAB % File: HW12_Problem8_liu2102.m % Date: 1 December 2017 % By: Erica Liu % liu2102 % Section: 2 % Team: 35 % % ELECTRONIC SIGNATURE % Erica Liu % % The electronic signature above indicates that the program % submitted for evaluation is my individual work. I have % a general understanding of all aspects of its development % and execution. % % This program will predict the concentration of dissolved oxygen (DO) in % mg/L in the Wabash in a given amount of days using a given formula. % It will indicate whether the concentration is between a certain range. clc clear all %constants given by the problem dosat = 9; k1 = 0.2; k2 = 0.4; l0 = 25; d0 = 4; %print the first 3 lines fprintf('DO in Wabash in mg/L:\n'); fprintf('Day DO\n'); fprintf('-----------\n'); for t =1:20 %calculate the DO based off of the formula given total = dosat - ((k1*l0)/(k2-k1))*(exp(-k1*t)-exp(-k2*t))-d0*exp(-k2*t); total = round(total,2); %round the calculation to 2 decimal places if total >= 6 && total <= 8 %determine whether the value is between 6 and 8 inRange = " *"; else inRange = " "; end fprintf('%2d %.2f%s\n', t, total, inRange); %print result end