MECE-117-02 Intro to Programming for Engineers
Homework Assignment #1
Elicia Esmeris
Jan 23, 2025
Problem #1 (Studio 01, Exercise #2)
Create an algorithm, in the form of a flowchart, for finding the piston height as a function of
crankshaft angle of the four-stroke engine described during Studio 01. Your algorithm should
include repeating the calculation for crankshaft angles from 180° to 360° (the compression
stroke). Your flowchart should include all of the equations necessary for these calculations (you
do not need to evaluate the equations, just solve them algebraically for the variable of interest
and write them out as part of your flowchart).
clc
clear
a = 1.12;
b = 2.34;
c = 9.2 * 10^(-2);
d = sqrt(3); %square root = sqrt()
f = -3.2;
h = pi/4; %pi = pi
x = 1 + (1/b) - (c/f^2)
y = (((a*b)/(2*c)*abs(f)))^(1/4) %absolute value = abs()
r = 1/((1/a)+(1/b)+(1/c)+(1/d))
s = log((b-c)/(d-c)) %ln = log
v = d * exp(1)^f %e = exp(1)
w = d * (acos(c)-h) %cos^-1 = acos
MATLAB command window output:
x=
1.4184
y=
2.5983
r=
0.0783
s=
0.3153
v=
0.0706
w=
1.2008
clear
clc
a = input('enter coefficient a')
xlo = input('enter lower limit of integration xlo')
xhi = input('enter upper limit of integration, xhi')
%compute arguement, compute terms, and combine terms for upper limit as
%shown in flowchart
argh = pi/4 - (a*xhi) / 2;
term1 = (xhi / a) * (cot(argh));
term2 = (2 / (a^2)) * log(abs(sin(argh)));
intglh = term1 + term2;
%compute arguement, compute terms, and combine terms for lower limit as
%shown in flowchart
argl = pi/4 - (a*xlo) / 2;
term3 = (xlo / a) * (cot(argl));
term4 = (2 / (a^2)) * log(abs(sin(argl)));
intgll = term3 + term4;
%combine lmits
intgl = intglh - intgll;
%disp limit
disp(intgl)
MATLAB command window output:
enter coefficient a 2
a=
2
enter lower limit of integration xlo 0
xlo =
0
enter upper limit of integration, xhi pi
xhi =
3.1416
1.5708
clc
clear
%a = 9.385 b = 0.09044
%[atm*L^2/mol^2]
%[L/mol]
n = input('enter number of moles n'); %mols of propane n
V = input('input volume V'); %volume in liters
T = input('input temperature T in K'); %temperature in kelvin
a = input('molecular attraction coefficient, a:__atm*L^2/mol^2');
b = input('molecular volume coefficient b: __L/mol');
R = input('ideal gas constant R: __L*atm/K');
pideal = (n*R*T)/V;
pwaals = ((n*R*T)/(V-n*b))-((a*n^2)/(V^2));
pctchg = (pwaals - pideal)/pideal*100;
disp('the ideal gas pressure is ')
disp(pideal)
disp('the Van der Waals pressure is ')
disp(pwaals)
disp('the percent change is ')
disp(pctchg)
MATLAB command window output:
enter number of moles n 2.0
input volume V 22.4
input temperature T 295
molecular attraction coefficient, a:__atm*L^2/mol^2 3.607
molecular volume coefficient b: __L/mol 0.04286
ideal gas constant R: __L*atm/K 0.08206
the ideal gas pressure is
2.1614
the Van der Waals pressure is
2.1409
the percent change is
-0.9462
Problem 5:
Line 29: rod to rad
theta = theta + 30;
theta_rad = theta * pi / 180; %3
sin_theta = sin(theta_rad);
disp(sin_theta)
Line 50: rod to rad
theta = theta + 30;
theta_rad = theta * pi / 180;
sin_theta = sin(theta_rad);
disp(sin_theta)
Line 81: rounding error, MATLAB should display 0
theta = theta + 30;
theta_rad = theta * pi / 180;
sin_theta = sin(theta_rad);
disp(sin_theta)