Contents

Aaron Klapheck

Ch 4. Assignment #8 due 10/31

clear, clc
Date = date
Date =

29-Oct-2007

Problem 4

% Given
x = 6;

% Find the results of the following operations

% a.
z = (x<10)
if z == 1
    disp('a. is true')
else
    disp('a. is false')
end

% b.
z = (x==10)
if z == 1
    disp('b. is true')
else
    disp('b. is false')
end

% c.
z = (x>4)
if z == 1
    disp('c. is true')
else
    disp('c. is false')
end

% d.
z = (x~=7)
if z == 1
    disp('d. is true')
else
    disp('d. is false')
end
z =

     1

a. is true

z =

     0

b. is false

z =

     1

c. is true

z =

     1

d. is true

Problem 6

% Given
x = [10, -2, 6, 5, -3];, y = [9, -3, 2, 5, -1];

% Find the results of the following operations

% a.
z = (x<6)

% b.
z = (x<=y)

% c.
z = (x==y)

% d.
z = (x~=y)
z =

     0     1     0     1     1


z =

     0     0     0     1     1


z =

     0     0     0     1     0


z =

     1     1     1     0     1

Problem 8

% Given price (in $) of stock per day for ten days
price = [19,18,22,21,25,19,17,21,27,29];

% Find number of days the stock price is above $20
z = (price>20)
days = z*ones(10,1)
z =

     0     0     1     1     1     0     0     1     1     1


days =

     6

Problem 10

% Given price (in $) of three stocks (A, B, and C) per day for ten days
price_A = [19,18,22,21,25,19,17,21,27,29];
price_B = [22,17,20,19,24,18,16,25,28,27];
price_C = [17,13,22,23,19,17,20,21,24,28];

% a. Find number of days stock A is more than stock B and C.
days_and = ((price_A > price_B) & (price_A > price_C))*ones(10,1)

% b. Find number of days stock A is more than stock B or C.
days_or = ((price_A > price_B) | (price_A > price_C))*ones(10,1)

% c. Find number of days stock A is more than stock B or C, but not both.
days_or_not_and = (days_or) - (days_and)
% or c. can be done this way
days_or_not_and = xor((price_A > price_B),(price_A > price_C))*ones(10,1)
days_and =

     4


days_or =

     9


days_or_not_and =

     5


days_or_not_and =

     5

Problem 11

% Given
x = [-3, 0, 0, 2, 5, 8];, y = [-5, -2, 0, 3, 4, 10];

% Find the following

% a.
z = y<~x
% b.
z = x&y
% c.
z =x|y
% d.
z = xor(x,y)
z =

     1     1     1     0     0     0


z =

     1     0     0     1     1     1


z =

     1     1     0     1     1     1


z =

     0     1     0     0     0     0