MATLAB HOMEWORK

profiled7_93
hw_5.docx

Use MATLAB to solve each problem by writing script files; copy and paste the script file AND the results in the Command Window and/or plot in the Figure Window to a WORD document that has your name and section in the headers of each page and the page number in each footer. Edit the output to remove extra lines and empty spaces. The script files SHOULD have comments for easy readability; take a print out of the Word file and staple before submission.

1. The height and speed of a projectile launched with a speed of v0 at an angle A to the horizontal are given by:

h(t) = v0t sin A –0.5gt2

v(t) =

where g is the acceleration due to gravity. The projectile will strike the ground when h(t) = 0, which gives the time to hit thit = . Suppose that A = 30, v0 = 40 m/s, g = 9.81 m/s2. Use MATLAB relational and logical operators to find the times when

a. The height is no less than 15 m.

b. The height is no less than 15 m and the speed is simultaneously greater than 36 m/s.

c. The height is less than 5 m or the speed is greater than 35 m/s.

d. Verify your answers by plotting h(t) and v(t) versus t with the same axes.

2. The price, in dollars, of a certain stock over a 10-day period is given as:

price = [19,18,22,21,25,19,17,21,27,29].

Suppose you owned 1000 shares at the start of the 10-day period, and you bought 100 shares every day the price was below $20 and sold 100 shares every day the price was above $25. Use MATLAB to compute (a) the amount you spent in buying shares, (b) the amount you received from the sale of shares, (c) the total number of shares you own after the 10th day, and (d) the net increase in the worth of your portfolio.

3. Use a for loop to plot the following function, over the interval –2 x 6.

for x < -1

= 2 + cos(x) for -1 x < 5

= 10(x-5) + 1 for x 5

The variable y represents height in kilometers, and the variable x represents time in seconds. Include title, grid, and axis labels.

4. Electrical resistors are said to be connected “in series” if the same current passes through each and “in parallel” if the same voltage is applied across each. If in series, they are equivalent to a single resistor whose resistance is given by

R = R1 + R2 + R3 + R4 + …+ Rn

If in parallel, their equivalent resistance is given by

Write an m-file that prompts the user for the type of connection (series or parallel), the number of resistors n, the values of resistors, and then computes the equivalent resistance.

5. Write a program in a script file that calculates the cost of renting a car according to the following price schedule:

Type of car

Rental period

1-6 days

7-27 days

28-60 days

Class B

$27 per day

$162 for 7 days, +$25 for each additional day.

$662 for 28 days, +$23 for each additional day.

Class C

$34 per day

$204 for 7 days, +$31 for each additional day.

$284 for 28 days, +$28 for each additional day.

Class D

Class D cannot be rented for less than 7 days.

$276 for 7 days, +$43 for each additional day.

$1,136 for 28 days, +$38 for each additional day.

The program asks the user to enter the rental period and the type of car. The program then displays the cost. If a period longer than 60 days is entered, a message “Rental is not available for more than 60 days” is displayed. If a rental period of less than 6 days is entered for class D, a message “Class D cars cannot be rented for less than 6 days” is displayed.

Run the program nine times for the following cases:

Class B, for 3, 14, and 50 days. Class C, for 20, 28 and 61 days. Class D for 6, 18, and 60 days.

)

1

(

+

=

x

e

y

n

3

2

1

R

1

....

R

1

R

1

R

1

R

1

+

+

+

+

=

2

0

2

0

sin

2

gt

A

gt

v

v

+

-

A

g

v

sin

2

0