M171 - Alexiades - UTK
Lab 2 ( as PDF )
Scripts, I/O, evaluating formulas
(always read the entire Lab before you start working on it)
(create folder Lab2 and work inside it)
A. Matlab scripts
Matlab programs are called "m-files" or "scripts".
They are PLAIN TEXT (ascii) files with name ending in ".m",
like, file_name.m .
They contain matlab commands, like you would enter in the command window, along with comments to document what is being done.
Learn about matlab scripts: work through
D: chap.2: §2.1-2.6 and b: chap.8
B. Work to do
In this lab you will be evaluating several formulas, in a script
formulas.m .
For each part: ask the user to input the needed values,
evaluate the formula using appropriate Matlab operations,
and print out the result nicely, using fprintf .
For clarity, insert a label for each part: % (a), % (b), etc,
and print a separation line after each part,
like:
disp('==========================');
or fprintf('========================= \n')
Figure out how to do it first on paper, then try it on Matlab.
Then insert it into the script, and
insert appropriate comments.
Formulas to evaluate:
(a) Find the volume of a cylinder of diameter 2.4 and height 4.2.
(V = π r2 h).
(b) Evaluate the rational function
at x=0.6 .
[ in case it does not display as a fraction on your browser, it is:
y = ( x3−x2+x−4.3 )
/ ( x2 + 0.005x−3.4 ) ]
(c) With r1 = 100 , r2 = 200 ,
r3 = 300, evaluate
,
= total resistance of three resistors in parallel.
[ in case it does not display as a fraction on your browser, it is: R = 1 / ( 1/r1 + 1/r2 + 1/r3 ) ]
(d) Find the Cartesian coordinates (x, y) of a point with polar
coordinates ( r=−0.5 , θ=3π/4 ):
x = r cosθ , y = r sin θ .
(e) A formula of your choice with at least two input variables.
C.
Prepare the file Lab2.txt for submission:
Once you have your program working as you want, and well-commented:
1. Turn on diary: >> diary Lab2.txt
2. Insert (as comment lines): Your Name, Lab2, Date
3. Insert a listing of your program in the file:
>> type formulas.m
4. Run your program: >> formulas
and enter all the data, etc.
5. Close the diary: >> diary off
6. Using a PLAIN TEXT editor, edit the file Lab2.txt
to clean it up, label each part: (a), (b), etc,
leaving only the correct version of
what is asked for above.
D. Submit it on Canvas before the due date.