0% found this document useful (0 votes)
79 views

Er Or: 1. (10) Assume First That The Following Instructions Have Already Been Entered Into MATLAB

The MATLAB commands to compute the area of the shaded region bounded by the y-axis, x-axis, constant K, and function y(t) are: 1) Define the integral from 1 to b of max(y(t)-K,0) dt to calculate the area above K. 2) Evaluate the integral numerically using quad to obtain the area. 3) Subtract the area below K, which is K*(b-1), from the total area.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Er Or: 1. (10) Assume First That The Following Instructions Have Already Been Entered Into MATLAB

The MATLAB commands to compute the area of the shaded region bounded by the y-axis, x-axis, constant K, and function y(t) are: 1) Define the integral from 1 to b of max(y(t)-K,0) dt to calculate the area above K. 2) Evaluate the integral numerically using quad to obtain the area. 3) Subtract the area below K, which is K*(b-1), from the total area.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

(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:

[m, n] = size (A) i

Now give the MATLAB commands to:


(a) Create an m x 1vector u containing the integers 1through m.

(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.

(d) Add 2 to those entries in A that are less than 5.

(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.

a= [I ,-6, -7, ',-It,Ll


r -::
roo~ LeA) ;
(ec;l z: r(~bs(i(v:'\1}((') (\fe-/))
XI -:: hiY'l (n:~,) ;
X'I -e, Mc.x ( r-e", \ ) ;

(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' ~) ;

G.x. -:: b; II (; , 3> L~ ~ """ov. + -:/.--0, 0 a-~S)


1\

rlv.t.::'" JV1MlO-V"IOI.-\I'\+)'" StA""1Ctc-w:);


cH~~(\T6~1 ()(..~~.::);
d ir p ( c;(t.1 f.) r
6. (15) Suppose that the function file bounds. m and the script file main. m as indicated below are in
the current directory. If main. m is "run", what would you expect to see in the command window?

main.m bounds.m

clear; function [beneath,above] = bounds (x)


X= [1: .1: 2] ; %function to find glb and lub for x
n=S; [n,m]=size(x) ;
[xl,xu]=bounds(2.9) ; if (n>l)&(m>l)
disp('lower upper'); error('Function not valid for
di sp ([xl,xu] ) ; 2-D arrays');
z=[3.S,-1.4,8.9] ; else
[zl,zu]=bounds(z) ; above ce i I (x) ;
e

disp( [zl',zu']); beneath=floor(x) ;


disp (n); end
a= [4.2 ,-1 .1 ;3 .7 ,-6 .3] ;
[al,au]=bounds(a) ;
disp( [al,au]);
disp(n) ;

\ 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
.---------~--~------~---=~--------==~=---------------------~-~

7. (20) To the right is a plot of a constant K and a


function y(t), both previously defined. Give the
MATLAB commands to compute the area of the
shaded region bounded by the y-axis on the left, the
x-axis above, the constant K below, and the function
y(t) on the right. (Solve this using MATLAB ~
instructions; don't try reading answers off the plot, ~
and don't assume the formula for y(t)!)

+, -: +t.O·~ (@Y I {)

+6-.": tl-e("o (@. 'I ~f :) t (1, k) ;

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(

o/a So - K f,.J' I lot. poS'i h V


~r~c, ~ ~ ttuc.d (@Y I I( t-<., [1, [1, K);
0V(Ct ~ o("~~ I + o..('~C\ :(

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

You might also like