Er Or: 1. (10) Assume First That The Following Instructions Have Already Been Entered Into MATLAB
Er Or: 1. (10) Assume First That The Following Instructions Have Already Been Entered Into MATLAB
(10) Assume first that the following instructions have already been entered into MATLAB:
x = [1; 3; 5; I);
Y = [2, 4, 6, 1];
A = [4,5,1,0; 2,3,1,2];
Now assume that the following instructions are entered into MA TLAB in the order given. Under each
one, write the output that MATLAB will produce. You can omit the "ens =". If the entry will result in
an error, write "error".
A. x. *y_ F. [1:-1:-1]
error
B. y*x G. A(:, 2)
v (2,
L.\--
C.
1) t-
A.*x
C ~ ."))
IL1-)O
.j. (b 'J)
+-(
f- ( I ' I)
-=-lLtsl CD
H. A(4)
J.,
D. A*x I. y. *A(2, :)
E. A*y J. A(l,2:3)
Page 2 of 7
2. (15) Suppose that A is a previously defined matrix, and assume that the following command has
already been entered into MATLAB:
(b) Create a new (m--L) x n matrix C as follows: the first rows are the same as A, while the last
row contains the sums of the corresponding columns in A.
(c) Create a new 2x2 matrix D containing the corresponding entries in the upper left corner of A.
(e) Assign to the variable big the largest entry in the matrix A.
Page 3 of 7
3. Consider the polynomial p (x) = x5 - 6x4 -7x3 +6x2 - 8x+4. Give the MATLAB commands to:
(a) (10) Assign to xl the smallest real root and to xr the largest real root. A root should be
considered real if its imaginary part is less than 10-7 in absolute value.
(b) (10) Now, if xl is not equal to xr, plot p (x) between xl and xr using 100 evenly spaced
points, making it Figure 2. Use a dashed red line, title the plot "my Polynomial", label the x-axis "bob"
and the y-axis "mary".
X-=)\V)Sf'~cc(xl,xr, l<l());
y :. pol" vc. (Cl,)<)
t ·5v.re ('l) I P\Q+(X, Y r: - -' ; ( +i He.('
F My P~lyn&~it;j'),)C lc..b~1(' h 06') ( yl c..bel ( Mttry');
end.
4. (8) The ideal gas law gives the pressure of an ideal gas as p = ~T where T is absolute
temperature, V is the volume per mole and R is the universal gas constant in appropriate units.
Vanderwaal's equation modifies this as p = RT - --;- where a and b are known as the
V-b V
Vanderwaals constants.
Define a MATLAB function that will compute both the ideal pressure and the Vanderwaals pressure.
Do not assume any global variables, but do prepare for T and V to be vectors.
pidc.c.l::: (R ·T)~/V ;
~ v CA () -:: (( R ' T). / (V ~b J) - ( (A. I V, A ~) ;
Page 4 of 7
5. At the Friendly Supermarket, each customer is given a ticket showing, for each different item
purchased, the quantity of that item, the unit price of that item, and a 1 or a 0 depending on whether
that item is taxable (1 if it is, 0 if it is not). Thus, the ticket can be represented by a three-column
matrix. Suppose that a plain text file named ticket. txt contains the ticket for a customer.
(a) (2) Give the MATLAB command to read the ticket from the file, creating the matrix named bill.
(b) (10) Give the MATLAB commands to determine and display the total amount due, assuming that
taxable items are assessed an 8.25% tax.
tA MOlAl')\- -;:. bill (.' # I L'If- hill <. ~ I' ~) ;
main.m bounds.m
\ o LJef'
:J'
11
, .1 \
E ""'Or tAJi"'S =.) bo v..~ d r
FI.A1'\c+~()V"\ Ylf)..L V,,\;~ to-r J¥i)
Page 5 of 7
c..V"V'C.V5
.---------~--~------~---=~--------==~=---------------------~-~
+, -: +t.O·~ (@Y I {)
G.('ec.' ::- - K · +, ~ ~ JIA S -\- Co. r-e.c,...tc (\5 j e I no+-e +h4+ th e, 5 rc.~~ k I; (\c.5~ ~I'v(
tv! n c-L f; le
-L
tV'
t(v{~ b VOl
0 V\
L 0"-,, \ J -= Y k ( 6,11)
fk, Y'=)
0(A-t--:: y(-h) - k;
Page 6 of 7