SOLN

ENGR 17
Test 1
SOLNS
CLOSED COMPUTER – DOUBLE SHEET OF NOTES -- SHORT ANSWER
1) Express the following calculation of P as a single matlab statement. Assume V is a vector and all
other variables are scalar.
P = R*T./(V - b) – a./(sqrt(T)*V.*(V + B))
2) Write the Matlab statement that creates these vectors, using the :, ‘ , [], and ; symbols, and any
other matlab commands where appropriate.
a) [ 5 10 15 20 25 30 35]
5:5:35
b)
6
7
5
2
[6 7 5 2]'
c) 7 values evenly spaced between 0 and pi
(column vector)
linspace(0,pi,7)
3) If the Law of Sines states that sin(a)/A = sin(b)/B, write a matlab expression to determine x in
degrees
x = asind( 22* sind(80) / 25 )
__________________________________________________
4) Make a Function file that computes the function
where x repersenting an angle in degrees. Call it sin2x2. For example sin2x2(30) will result in 0.25
since the sine of 30 degrees is 0.5, while sin2x2(45) will result in 0.5
Make sure the function will work with vector input. Write the function as you would enter into the
file sin2x2.m
function y = sin2x2( x )
y = sin(x).^2;
5) Now write statements that will use your function file from 4) to plot the curve
over the range -350 to 360.
ang = [ -360:360;
y = sin2x2( ang)
plot( ang, y )
6) The following chart is taken from: http://data.giss.nasa.gov/gistemp/station_data/ and shows the
annual mean temperature of San Francisco from 1880 to 2011.
Suppose the vector sftemp contains all the
temperature data shown, and the vector year
contains the corresponding years. Write matlab
statements to determine:
a) the total number of years in the data set:
length(year)
b) the number of years when the average
temperature was above 14 degrees:
sum ( sftemp > 14) OR
length ( find (sftemp > 14 ) )
c) the average temperature from 1920 to 1980
(use the mean function to compute average)
mean ( sftemp ( year >= 1920 & year <= 1980 ) )