Sheet-02 EPM486
Sheet-02 EPM486
(1) Suppose that x = 6. Find the results of the following operations by hand and
use MATLAB to check your results.
(a) z = (x<10) (b) z = (x = = 10)
(c) z = (x>= 4) (d) z = (x ~ = 7)
(2) For the arrays x and y given below, use MATLAB to find all elements in x
that are greater than the corresponding elements in y.
x = [-3 0 0 2 6 8] and y = [-5 -2 0 3 4 10]
(3) The array price given below contains the price in dollars of a certain stock
over 10 days. Use MATLAB to determine how many days the price was above
20$.
Price = [19 18 22 21 25 19 17 21 27 29]
(4) The array price_A, price_B and price_C given below contain the price in
dollars of three stocks over 10 days.
(a) Use MATLAB to determine how many days the price of stock A was
above both the price of stock B and the price of stock C.
(b) Use MATLAB to determine how many days the price of stock A was
above either the price of stock B or the price of stock C.
(6) An ideal diode is used in a half wave rectifier circuit as shown in the figure.
The voltage VL across the load RL is given by:
VL = V S if VS > 0 and VL = 0 if VS = 0
Suppose that the supply voltage is
VS = 3 e-t/3 sin (π t) volts where t is in seconds.
Write a MATLAB program to plot the voltage VL versus t for t varies from 0 to 10
seconds.
Diode
VS RL VL
1
(7) The following m.file is a function file (linspace) for the creation of linearly
spaced vector. The program does not work properly due to at least four
mistakes. Find them then rewrite the program with errors after correction.
linspace.m
linspace (d1,d2,n)=y;
% linspace is linearly spaced vector
% linspace (x1,x2) generates a row vector
of 100 elements linearly
% equally spaced points between x1 and x2
%
% linspace (x1,x2,n) generates n points between
x1 and x2
% see also LOGSPACE
if nargin = 2
n = 100;
end
y=[d1+(0:n-2)*(d2-d1)/(n-1) d2];
end
return
(9) The equations describing the circuit shown in the figure are:
I1 I2 I3
- V1 + R 1 I 1 + R 4 I 4 = 0 R1 R2 R3
- R4 I4 + R2 I2 + R5 I5 = 0 I4 I5
+ +
- R5 I5 + R3 I3 + V2 = 0 R4 R5
V1 V2
I1 = I 2 + I 4 – –
I2 = I 3 + I 5
(10) Consider the following script. Fill in the lines of the table shown below with
the values that would be displayed immediately after the while statement if
you run the script file. Write in the values of the variables each time the while
statement is executed. You might need more or fewer lines in the table. Then
use MATLAB to check your answer.
K = 1; b = -2; x= -1; y = -2;
while k<=3
2
k, b, x, y
y = x^2 - 3;
if y<b
b = y;
end
x = x +1;
k = k +1;
end
Pass k b X y
First
Second
Third
Fourth
Fifth
(14) Generate a matrix that each element is a function of its number of row and
number of column as follow
A (i , j) = i3 + j3 .