MATLAB Assignments
MATLAB Assignments
MATLAB Assignments
Problem 1
1.1
Variables
1) IsBad VarName
2) 2CoolForSchool
3) IsBad?VarName
4) or
5) fourier
6) elif
7) sqrt
8) break
9) yourself
10) else
1.2
1) a: sub 1
2) a: PapaJohn
1.3
1)
2)
3)
4)
5)
6)
b: sub l
b: papajohn
A = [1, 2, 3; 4, 5, 6]
b = [1, 2; 3, 4; 5, 6]
c = [123; 456]
d = [1; 2; 3; 4; 5; 6]
E = [A; A]
F = [A, c]
Problem 1
(2pts) Numbers
Given the following IEEE-754-dened values (in base-10, dont worry), tell me what
number is constructed:
a)s=1, m=31416, b=10, e=-4
b)s=0, m=64, b=2, e=-6
Problem 2
2.1
Logicals
a) Checkbox
b) Cube
c) Square with lower case ab in it
d) Doubly-bisected square
2.2
a) R & T
b) S | T
c) S >= T
d) (R & S) < T
e) R =T
f) R == S
Problem 3
(6pts) Arrays
Problem 1
Polynomial Roots
1.1
1.2
Solve for the two imaginary roots (note that they are a pair of complex conjugates).
.........
Problem 2
(10pts) Triangles
HH c
H
HH
H
H
b
Given the information in Table 1, calculate the area, perimeter, and lengths of
sides b and c of each of the triangles.
Triangle Side a (m) Angle ac (Degrees)
1
1
30
2
1
50
3
2
20
4
3
45
5
5
60
.........
Problem 1
1.1
Save and rename the hw4 starter.m le, and use it as the beginning of your code.
Recall Eulers formula from analytical calculus: eix = cos(x) + i sin(x), where i is
the imaginary unit. A slight rearrangement yields:
sin(x) = i cos(x) i eix
(1)
Create a nested subfunction within the starter le that accepts one input argument
x (which may be a vector) and returns the sin function dened as above. Call
this function for input arguments of x=0:pi/4:2*pi and return the results to the
command window.
1.2
Subtract the standard MATLAB denition of sin(x) from the above denition for
the same input arguments and return the results to the command window. Think
about what this gure means for MATLABs denition of sine.
1.3
Corollaries of Eulers formula are the hyperbolic functions, sinh and cosh, which are
dened as:
ex ex
ex + ex
cosh(x) =
(2)
2
2
Using the same starter function, add anonymous functions mysinh(x) and mycosh(x)
which perform the calculations above. Evaluate these functions for input arguments
of x=-0.5:0.1:0.5 and return the output of both functions to the command window.
sinh(x) =
.........
Problem 1
Tricky Temperatures
Certain common temperature scales are relative, that is, with a zero dened against an arbitrary value. Others are absolute, taking their zero at the theoretical point where molecular
motion stops. The following functions must ask the user to specify the units on the inputs, with your code making the necessary adjustments to compute correctly. Faulty inputs
must be rejected (no complex temperatures and only certain scales admit negative). You
may either admit or reject vectors. You may use either if/else or switch/case structures. Use the menu command to call for inputs. Users must be oered options of degrees
Fahrenheit, Centigrade, Kelvin or Rankine. If in doubt about temperature scales, consult
Wikipedia or WolframAlpha. As always, name your function like asurite hw5.m.
1.1
A heat engine may not have a thermodynamic (1st Law) eciency greater than that of the
theoretical Carnot cycle. This cycle represents the ideal machine taking innite time to
move energy from a hot reservoir at TH to a cold reservoir at TC (perhaps the combustion
chamber of a turbine and ambient air). The Carnot/ideal eciency is dened using absolute
temperatures as:
TC
ideal = 1
(1)
TH
Write a function which accepts two inputs, TH and TC , and outputs the correct Carnot
eciency. Eq. 1 must be given absolute units of temperature. Your function must accept
any of the four input units above.
1.2
(10pts) Radiation
The blackbody radiation heat ux between two innite plates (or any pair of objects with
view factors of unity) is given by:
q = (TH4 TC4 )
(2)
where is the Stefan-Boltzmann constant, and TH and TC are the absolute temperatures
of the interacting black bodies. Given TH and TC as in Q1.1, calculate the output of q.
W
,
regardless
of
the
input
units.
Consult
Wikipedia,
The output must be in units of m
2
WolframAlpha, or a heat transfer book if you need help nding values of in appropriate
units.
Problem 1
1.1
Loops
The Taylor series allows the approximation of a function at unknown xvalues in the
region of a known value. Thus, if a is the known value and x is near a:
df
d2 f (x a)
+ ...
(x
a)
+
a
a
dx
dx2
2
which can be written compactly as:
f (x) f (a) +
f (x)
f (n) (a)
n=0
n!
(x a)n
(1)
(2)
where f (n) indicates the nth derivative of the function, and the exclamation mark
indicates the factorial. Conveniently, ex is its own derivative. Approximate e0.15
using the Taylor series and a while loop. Note that x = 0.15 is close to a convenient
known a value. Your allowable absolute error (error = |guess true|) is to be less
than or equal to 109 , and you must tell me how many terms in the Taylor series
were required to achieve convergence. (Suggest using disp)
1.2
The Fibonacci series is dened by creating the next term in the series as the sum
of the two prior. For example, if we began with 0 and 1, we would go like: 0+1=1,
1+1=2, 1+2=3, 2+3=5, and so on. Taking 1 as the rst term, 1 as the second term,
etc., write a for loop to calculate the 50th term in this series.
Problem 1
This assignment requires you to use the hw7 data.mat le, available on the HW
assignment page. To load the data in the le into MATLAB, simply save the le to
your working directory (something like Documents/MATLAB/MAE215, hopefully),
and then in your code type load hw7 data.mat.
In the MAT-le, temperature data are split into two matrices, TTC hw carrying heated-surface thermocouple data and Tref hw carrying refrigerant temperature
data. The ve columns of TTC hw are to be labeled B, C, D, F, and G, respectively.
The two columns of Tref hw are to be labeled Inlet and Outlet, respectively. Pressure data are carried in the two-column matrix p hw, and are to be labeled Inlet and
Outlet, respectively. Time is carried in the single-column matrix t.
1.1
Plot the time-temperature curves for all of the thermocouples in TTC hw. Provide
descriptive axis captions, a legend and a title. If possible, print your gure to PDF
for submission. Otherwise, saving as a JPG is acceptable.
1.2
Using subplot, display both inlet and outlet pressure vs. time on one subplot. In
the same gure, make a second subplot and display the inlet and outlet refrigerant
temperatures. For both subplots, provide descriptive axis captions (indicating which
axis belongs to which data), and provide legends and a title. If possible, print your
gure to PDF for submission. Otherwise, saving as a JPG is acceptable.
.........
Problem 1
This assignment requires you to use the hw8 data.csv le, available on the HW
assignment page.
1.1
(5 pts) Incoming
Using an appropriate command-line data reading function, have your M-le place the
contents of hw8 data.csv into the appropriate workspace of your M-le. Import
the columns of Time (s), Angle (rad), and Speed (m/s).
1.2
The data for time, angle, and speed are uniform random values, with directions
splattered around the compass. Working from dead reckoning, and assuming an initial
position of (0, 0), determine the mean x-displacement, the mean y-displacement, and
plot the course taken.
.........
Problem 1
On August 25th of 2012, America lost Neil Armstrong. He was the rst man on the
moon, a test pilot, naval aviator, professor, aeronautical engineer, and American hero.
On July 20, 1969, he and Buzz Aldrin walked on the moon, while Michael Collins orbited in the Command-Service Module. The le hw9 original armstrong.jpg
contains a photo of Neil taken by Buzz Aldrin on their way back to Earth. Like many
old images, its colors are somewhat distorted. It is a JPG, so it comes in RGB format.
1.1
1.2
Using the corrected image you obtained in part one, reduce it to black-and-white,
write the resulting image to disk (using imwrite) and submit your resulting JPG.
1.3
.........
Problem 1
Cell arrays are indexed general-purpose buckets. Create an M-le which puts the
following objects into one cell array:
1) A 100x100 magic square (use magic)
2) The string The 10th homework
3) A vector from 1 to 1000, spaced with increments of 0.1
4) The square of the vector dened in (3)
5) A structure array made by assigning an output while loading the MAT le from
Homework 7.
Next, call items 3 and 4 back from the cell array and plot them with vector (3)
on the x-axis, and vector (4) on the y-axis. No labels or legend are necessary.
.........
Problem 2
Next, call items 3 and 4 back from the cell array and plot them with vector (3)
on the x-axis, and vector (4) on the y-axis. No labels or legend are necessary.
.........
Problem 1
Boiling refrigerant in very small channels is an eective way to rapidly remove large
amounts of heat. Such devices are called microchannel evaporators. Large pressure
drops pose a signicant problem to the application of this technology, because small
channels have large resistance to ow (see Poiseulles Law for the basic idea, but it
scales as 1/D4 ).
A recent improvement in the eld of microchannel evaporators is the idea of
expanding the channel cross-section in the ow direction, letting the channel get
bigger as more refrigerant boils away to vapor. This improvement is optimizable for
maximum heat rejection, and seems to substantially and monotonically reduce the
pressure drop in such devices.
In this assignment, you will produce four linear ts to the four sets of data supplied
in the le hw11 dPm.txt. The le is comma-delimited, and has eight columns of
data; the odd columns are mass ow rates (g/s), the even are pressure drops (kPa).
The data come from the four microchannel evaporators employed to ascertain the
existence of an optimum expansion. They have progressively larger expansion angles,
and the nominal angle (in degrees) is noted in the column headers. Mass ow rate is
the independent (x-axis) variable.
On one gure, plot the four sets of data along with the MATLAB-derived linear
t of each (do not use plotyy). Label your axes, add a legend with four entries
identifying the nominal expansion rate, and title the gure Microchannel Pressure
Drop. Be sure to use dierent colors and tick-marks for the data sets, and make the
t lines the same color as the corresponding data set.
Note: - The zero- and half-degree expansions have one fewer data point than the
one- and two-degree. Do not include the resulting 0, 0 points in your t. You will see
what I mean when you import the data.
.........
Problem 1
1.1
(5pts) Circles
(1)
1.2
(5pts) Integration
Evaluate the following symbolically in MATLAB, and be sure the results display
in the command window:
100
dx
(2)
F =
x + x ln(x)
1
d
2
ln(cosh(x ))
G=
(3)
dx
a
x
H=
dx
(4)
3 sinh
3
0
.........
Problem 2
Create a cell array containing your symbolic objects F , G, and H from 1.2 above,
and create a structure containing the x and y objects from 1.1. Display both of these
objects in the command window.
.........