Exercise 6:

1.

The exercises here show the techniques of logical-indexing (indexing with 0-1 vectors). Given x = 1:10 and y = [3 2 6 9 8 3 8 5 7 0], execute and interpret the results of the following commands:

 

 

 

a. x(x > 3)

 

b. y(x <= 3)

 

c. (x > 5) & (x < 8)

 

d. x((x < 4) | (x >= 6))

 

e. y((x < 2) | (x >= 8))

 

f. x(y < 0)

 

 

2.

Given x = [3 14 9 10 -2 0 -12 9 7 1], provide the command(s) that:

 

 

 

a. set the values of x, which are positive, to zero

 

b. multiply the values of x, which are even numbers, by 4

 

c. set values of x, which are multiples of 3, to 3 (command rem may help)

 

d. extract the values of x, which are greater than 9, into a vector called y

 

e. set the values of x, which are less than the mean, to zero

 

f. set the values of x, which are above the mean, to their difference from the mean

 

 

3.

Create the vector x = randperm(35) and evaluate the following function using only logical indexing:

 

 

 

y(x)

= 2

if x < 6

 

= x - 4

if 6 <= x < 20

 

= 36 - x

if 20 <= x <=35

 

 

 

You can check your answer by plotting y vs. x with symbols. The curve should be a triangular shape, always above zero and with a maximum of 16. It might also be useful to try setting x to 1:35.

 

 

4.

Create a 3-D graphic similar to the 3-D visualization as shown below. Please make your graph as silimar as the following visualization in terms of shape, color, and lighting effect.

 

 

 

 

5. Combustion is the chemical process in which thermal energy is liberated by rapidly reacting an oxidant with a fuel. In stoichiometric combustion, a fuel is reacted with an exact amount of oxygen to completely combust the fuel. The table below lists the oxygen and air requirements for combustion of three types of hydrocarbon fuels.

 

Fuel Type

O2 Required (ft3/ft3 fuel)

Air Required (ft3/ft3 fuel)

CnH2n

1.50n

7.18n

CnH2n+2

1.5n+0.5

7.18n+2.39

CnH2m

n+0.5m

4.78n+2.39m

 

Write a function file (fuel.m) that has three input arguments and two output argument; where [O,A] = fuel(v,c,h) returns the amount of oxygen and air required to perform stoichiometric combustion. (where v is total volume required, c is number of carbon atom, & h is number of hydrogen atom)

 

 

Use your function to compute the cubic feet of oxygen and air required to combust:

5.4 ft3 butane (C4H10)

>> [O,A]=fuel(5.4,4,10)

O = 35.1000

A = 167.9940

2.1 ft3 acetylene (C2H2)

>> [O,A]=fuel(2.1,2,2)

O = 5.2500

A = 25.0950

0.7 ft3 propylene (C3H6)

>> [O,A]=fuel(0.7,3,6)

O = 3.1500

A = 15.0780