# Answers to Midterm Exam Mon 28 Feb 2005

notice: five out of eight correct answers make a perfect score

1. Suppose a medicine to reduce fever is effective in 80% after the first dosis and costs \$1. A temperature reading of more than two degrees above normal six hours after taking the first dosis requires a visit to the doctor which costs \$10.
Clinical tests for a new fewer reducing medicine reported a success rate of 95% after taking the first dosis.
1. Under the same circumstances as above, is a cost of \$2 for the new medicine justified? (hint: compute the expected loss of having a fever for both medicines.)
```  Expected loss of having fewer for the old medicine:
0.80 \$1 + 0.20 (\$1 + \$10) = \$3
Expected loss of having fewer for the new medicine:
0.95 \$2 + 0.05 (\$2 + \$10) = \$2.5

The patient is better off (moneywise) with the new medicine,
so the cost of \$2 is justified.
```
2. What is a fair price for the new medicine, taking into account its higher quality? Considering only money, at which price would you buy the new medicine?
```  Let P be the break even price (same expected loss for both).
3.0 = 0.95 P + 0.05*(P + 10) = P + 0.5 => P = \$2.5

When the price for the new medicine is below (or at) \$2.5,
we will buy it, otherwise when the price is higher than \$2.5,
```
```                                                        +--------+
|    /20 |
+--------+
```
2. A man decides to participate in a 1,000 mile car race through the desert. Because of the rough terrain and excessive speed, tires have a life time normally distributed with an average of 600 miles and standard deviation of 200 miles.
The man starts the race with 4 new tires and takes 4 spare tires with him. Given the expected life span of the tires, will he be able to finish the 1,000 mile race?
1. Use Maple or MATLAB to set up a simulation to decide the odds of the man being able to finish the race.
```   # Maple code, count number of successes
N := 10000; S := 0;
for k from 1 to N do
# one simulation with 8 new tires
tires := stats[random,normald[600,200]](8);
# we start race with first 4 tires
life := [seq(tires[i],i=1..4)];
# increase the life span of the lowest tires
for j from 1 to 4 do
life := sort(life);
life[1] := life[1] + tires[4+j];
end do;
# check if we are reaching the 1000 mile limit
reach := min(op(life));
if reach < 1000
then S := S+1;
end if;
end do;
```
2. Run the simulation 10,000 times and give the probability of reaching the finish.
```        S = 3729, so the probability is about .3729
```
```                                                        +--------+
|    /20 |
+--------+
```
3. Suppose we start with an empty savings account. At the last day of every month \$400 is deposited into the account. After the first deposit, 20% of the balance of the savings account is withdrawn at the first day of every month.
1. Set up the recursion relation for the balance B(n) at month n, after n deposits.
```    B(n) = .8*B(n-1) + 400,  B(0) = 0
```
2. Solve the recursion for B(n).
```    B(n) = .8*B(n-1) + 400
= .8*(.8*B(n-2) + 400) + 400
...
n-1
---
= (.8^n)*B(0) + 400 >   (.8)^k
---
k=0

= 400*(.8^n - 1)/(.8 - 1)
= 2000*(1 - .8^n)
```
3. In doing so, will we ever get rich? Is there a limit to B(n)?
```    We will never get more than \$2000.
```
```                                                        +--------+
|    /20 |
+--------+
```
4. A digital filter is causal, linear, and time-invariant.
1. Give the definition of a transfer function of a digital filter and illustrate with an example.
```     The transfer function of a digital filter
is the z-transform of the unit impulse response,
i.e.:
infty
-----
H(z) = >      h(k) z^(-k)
-----
k=0

where { h(0), h(1), h(2), ... } is the response of the
filter to { 1, 0, 0, ...}.

Example: the averaging filter is defined by
y(k) = (u(k) + u(k-1)/2
and has z-transform H(z) = (1+z^(-1))/2.

```
2. Show that a digital filter is entirely determined by the response of the unit impulse.
```     We write the input signal u as a linear combination
of delayed impulses d and apply the linearity of the filter:

y = F u
= F( u(0)*d(0) + u(1)*d(1) + u(2)*d(2) + ... )
= u(0)*(F d(0)) + u(1)*(F d(1)) + u(2)*(F d(2)) + ... )
= u(0)*{ h(0), h(1), h(2), ...}
+ u(1)*{ 0, h(0), h(1), h(2), ...}
+ u(2)*{ 0, 0, h(0), h(1), h(2), ...}
= { u(0)*h(0), u(0)*h(1) + u(1)*h(0),
u(0)*h(2) + u(1)*h(1) + u(2)*h(0), ...}
= { y(0), y(1), y(2), ... }

So we see that once h(k) is known, we can compute y(k)
from u(k) via the convolution operator '*' : y = h'*'u.

```
```                                                        +--------+
|    /20 |
+--------+
```
5. A boat rental company must place its orders for new boats for the next summer. There are three types of boats, depending on the number of seats, specified below:
```+-----------+-------------+-----------+---------+-----------+
| boat type |   storage   |  purchase | rental  |   need    |
|  #seats   |     area    |    cost   |  price  | for boats |
+-----------+-------------+-----------+---------+-----------+
|     1     | f(1)=2 ft^2 | c(1)=\$122 | p(1)=\$5 |  n(1)=20  |
|     2     | f(2)=3 ft^2 | c(2)=\$130 | p(2)=\$7 |  n(2)=15  |
|     3     | f(3)=4 ft^2 | c(3)=\$150 | p(3)=\$9 |  n(3)=10  |
+-----------+-------------+-----------+---------+-----------+
```
Boat i requires f(i) square feet to store, costs c(i) dollars to purchase and can be rented at p(i) dollars a trip. Our constraints are as follows. We need at least n(i) boats of type i, but have only 400 square feet to store the boats and our budget is limited to \$10,000.
1. Denote by x(i) the number of boats we will order of type i. Set up the linear programming model to determine the optimal composition of the fleet which maximizes the profit from renting, subject to our constraints.
```        max 5*x(1) + 7*x(2) + 9*x(3)
subject to
2*x(1) +   3*x(2) +   4*x(3) <=   400
122*x(1) + 130*x(2) + 150*x(3) <= 10000
- x(1)                       <=   -20
- x(2)            <=   -15
- x(3) <=   -10
```
2. Formulate the dual problem as a minimization linear-programming problem.
```        min 400*y(1) + 10000*y(2) - 20*y(3) - 15*y(3) - 10*y(5)
subject to
2*y(1) + 122*y(2) - y(3)               >= 5
3*y(1) + 130*y(2)        - y(4)        >= 7
4*y(1) + 150*y(2)               - y(5) >= 9
```
3. Solve the dual problem with MATLAB. Give the solution to the original problem.
```f = [400  10000  -20  -15  -10]';
A = [-2 -122 1 0 0;
-3 -130 0 1 0;
-4 -150 0 0 1;
-1   0  0 0 0;
0  -1  0 0 0;
0   0 -1 0 0;
0   0 0 -1 0;
0   0 0 0 -1];
b = [-5 -7 -9 0 0 0 0 0];
[y,lambda]=simlp(f,A,b)

y =

0
0.0600
2.3200
0.8000
-0.0000

lambda =

20.0000
15.0000
37.4000
165.4000
0
0
0
27.4000

The answer is x(1) = 20, x(2) = 15, x(3) = 37.4.
```
```                                                        +--------+
|    /20 |
+--------+
```
6. Sample u(t) = cos(2*pi*t) at intervals T = 1/8, as input u(k) = cos(2*pi*k/8), k=0,1,... to the filter y(k) = a*u(k) + b*u(k+1) + c*u(k+2), with three parameters: a, b, and c.
Determine the parameters a, b, and c
• (i) to change the frequency of the original signal, i.e.: y(k) = u(k+1), and
• (ii) to suppress the signal v(t) = cos(3*2*pi*t).
1. Set up the system of linear equations we need to solve to find a, b, and c, using 8 samples each for the conditions (i) and (ii). (hint: use MATLAB or Maple.)
```     We take the equation y(k) = a*u(k) + b*u(k+1) + c*u(k+2)
and evaluate it at the 8 samples, for the signal u(t) and v(t).
This gives 16 linear equations in 3 unknowns:

% MATLAB CODE:
dt = 2*pi/8;                                        % sampling interval
t0 = 0:dt:2*pi-dt;                                  % range for u(k)
t1 = dt:dt:2*pi;                                    % range for u(k+1)
t2 = 2*dt:dt:2*pi+dt;                               % range for u(k+2)
u0 = cos(t0); u1 = cos(t1); u2 = cos(t2);           % sample u(t)
v0 = cos(3*t0); v1 = cos(3*t1); v2 = cos(3*t2);     % sample v(t)
A1 = [u0' u1' u2'];                                 % 1st conditions
b1 = u1';
A2 = [v0' v1' v2'];                                 % 2nd conditions
b2 = zeros(8,1);
A = [A1; A2];                                       % A x = b
b = [b1; b2];
```
2. Use MATLAB or Maple to solve this overconstrained linear system.
```x = A\b

x =

0.3536
0.5000
0.3536
```
```                                                        +--------+
|    /20 |
+--------+
```
7. Suppose we have \$100,000 to invest. We have two options. Either we could deposit the amount in an account which would yield us 7% each year in interest; or we could buy a house and make it available for rental. Assume the value of the house increases with 5% each year and the house yields \$8,000 a year in rent (after deducting taxes and upkeep costs).
1. Which option is better on the short run (a couple of years)? What if we can keep the house for 20 years? Which option is then better?
```     Use the Maple functions, for the options (A = 1st, B = 2nd):
A := n -> 100000*(1 + 0.07)^n
B := n -> 100000*(1 + 0.05)^n + 8000*n

Evaluate in 2nd year:
A(2) = \$114,490 < \$126,250 = B(2)
Evaluate in 20th year:
A(20) = \$386,968 < \$425,330 = B(20)

Option B, buying the house is better in the short run,
even at year 20 it is still the better option.
```
2. Calculate the number of years when both options have the same return. What is your advice? If we buy, how long should we keep the house?
```     A plot of A and B reveals that the two curves intersect
between year 24 and year 25.  Evaluation of A and B gives

A(24) = \$507,236.70 < \$514,509.99 = B(24)
A(25) = \$542,743.26 > \$538,635.49 = B(25)

We should sell the house in year 24.
```
```                                                        +--------+
|    /20 |
+--------+
```
8. Consider a market with demand q = 5 + 10/p and supply q = p^2 - 3.
1. Compute the equilibrium price and revenue for the producer.
```     D(p) = 5 + 10/p,  S(p) = p^2 - 3
D(p) = S(p) gives the equilibrium price p = \$3.32 (Maple)
Revenue = p*S(p) = 3.32*8.01 = 26.59
```
2. Suppose the government gives the producer a subsidy of \$1 per item. Describe the effect of this subsidy to the supply, equilibrium price and revenue function.
```     new supply nS := S(p+1) = (p+1)^2 - 3
new equilibrium price: \$2.47
new supply: \$9.05
new revenue: \$22.35

With a subsidy, the producer will supply more goods,
which will decrease the price and the revenue.
```
3. Of every dollar the government spends on subsidy, how much goes to producer, and how much to the consumer?
```     The benefit of the consumer is the price decrease:
\$3.32 - \$2.47 = \$0.85.
So the consumer gets 85 cents of the \$1 subsidy per item,
the other 25 cents goes to the produces who loses revenue.
```
```                                                        +--------+
|    /20 |
+--------+
```