Docsity

Math 128a Homework 4: Solving Systems of Equations and Calculating Interest Rates, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
Math 128a - Homework 4 - Due Sept 28 at the beginning of class
1) Section 3.3, Problem 8
Answer: We have to show that, if V1=a1and Vi=Vi−1(1 + r)+aifor i>1 then, letting
x=1+r:
Vn=
n
i=1
aixn−i
Proof by induction: When n= 1 this just says V1=a1which we are given. Assume the statement
is true for n−1. Thus
Vn−1=
n−1
i=1
aixn−1−iso :
Vn=(
n−1
i=1
aixn−1−i)x+an
=(
n−1
i=1
aixn−i)+anxn−n
=
n
i=1
aixn−i
2) You have just had a new baby, and realize that you have to start saving a lot of money to afford to
send the child to college. Planning for the worst case, you ask yourself how much you would have to
save to send your child to Stanford in 18 years. Assuming 7% inflation for college tuition (a widely
recommended number for concerned parents), you compute that the current $30,000/year cost of
Stanford (out-of-date cost, but good enough for this question) will rise to $30000 ·1.0718 ≈$101398
per year, or $405592 for four years. By eating a lot of macaroni and cheese, you figure you can save
$10000/year to invest for the next 18 years. Assume that all your investment income will be taxed
at a 20% rate at the end of 18 years. What interest rate do you need to get to have saved $405592,
after taxes, after 18 years? Given that the historic rate of return of the stock market is around
10%, do you expect to have saved enough? Hint: Use the formulation from the last question. Note
that you pay tax only on the interest you earn, not the $180000 you invest (which would be double
taxation). Explain how you got your answer; “I plugged it into an HP-12C financial calculator” is
not good enough. We note that the solver for this problem on the HP-12C was designed by Prof.
W. Kahan in our department.
Answer: This problem can be cast in terms of the previous problem letting ai=10
4.Given
an interest rate rand letting x=1+r, after 18 years we will have saved
V18 =10
4
18
i=1
x18−i
=10
4(x17 +x16 +...+x2+x+1)
Then we take 20% in taxes off, but we don’t get taxed on the total amount we put in, so we are
left with V18 −(0.2)(V18 −18(104)) = 0.8·V18 +3.6·104; we want to find an rthat makes this
quantity at least 405592. In other words, solve the following for xand then set r=x−1:
0.8(104)x17 +0.8(104)x16 +...+0.8(104)x+ ((0.8·104+3.6·104)−405592) = 0
1
pf3
pf4
pf5

Partial preview of the text

Download Math 128a Homework 4: Solving Systems of Equations and Calculating Interest Rates and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Math 128a - Homework 4 - Due Sept 28 at the beginning of class

  1. Section 3.3, Problem 8 Answer: We have to show that, if V 1 = a 1 and Vi = Vi− 1 (1 + r) + ai for i > 1 then, letting x = 1 + r:

Vn =

∑^ n

i=

aixn−i

Proof byinduction: When n = 1 this just says V 1 = a 1 which we are given. Assume the statement is true for n − 1. Thus

Vn− 1 =

n∑− 1

i=

aixn−^1 −i^ so :

Vn = (

n∑− 1

i=

aixn−^1 −i)x + an

n∑− 1

i=

aixn−i) + anxn−n

∑^ n

i=

aixn−i

  1. You have just had a new baby, and realize that you have to start saving a lot of money to afford to send the child to college. Planning for the worst case, you ask yourself how much you would have to save to send your child to Stanford in 18 years. Assuming 7% inflation for college tuition (a widely recommended number for concerned parents), you compute that the current $30,000/year cost of Stanford (out-of-date cost, but good enough for this question) will rise to $30000 · 1. 0718 ≈ $ per year, or $405592 for four years. By eating a lot of macaroni and cheese, you figure you can save $10000/year to invest for the next 18 years. Assume that all your investment income will be taxed at a 20% rate at the end of 18 years. What interest rate do you need to get to have saved $405592, after taxes, after 18 years? Given that the historic rate of return of the stock market is around 10%, do you expect to have saved enough? Hint: Use the formulation from the last question. Note that you pay tax only on the interest you earn, not the $180000 you invest (which would be double taxation). Explain how you got your answer; “I plugged it into an HP-12C financial calculator” is not good enough. We note that the solver for this problem on the HP-12C was designed byProf. W. Kahan in our department. Answer: This problem can be cast in terms of the previous problem letting ai = 10^4. Given an interest rate r and letting x = 1 + r, after 18 years we will have saved

V 18 = 104

∑^18

i=

x^18 −i

= 104 (x^17 + x^16 +... + x^2 + x + 1)

Then we take 20% in taxes off, but we don’t get taxed on the total amount we put in, so we are left with V 18 − (0.2)(V 18 − 18(10^4 )) = 0. 8 · V 18 + 3. 6 · 104 ; we want to find an r that makes this quantityat least 405592. In other words, solve the following for x and then set r = x − 1:

0 .8(10^4 )x^17 + 0.8(10^4 )x^16 +... + 0.8(10^4 )x + ((0. 8 · 104 + 3. 6 · 104 ) − 405592) = 0

To find the roots of this polynomial I ran the following line on Matlab:

 p = [.8e4*ones(1,17), .8e4 + 3.6e4 - 405592]; roots(p) ans = -1.2738+ 0.2321i -1.2738- 0.2321i -1.1080+ 0.6653i -1.1080- 0.6653i -0.7989+ 1.0096i -0.7989- 1.0096i -0.3887+ 1.2192i -0.3887- 1.2192i 0.0667+ 1.2665i 0.0667- 1.2665i 0.5044+ 1.1461i 0.5044- 1.1461i 0.8625+ 0.8752i 0.8625- 0.8752i 1.0852+ 0.4904i 1.0852- 0.4904i

So the root that matters to us is x = 1.1013, or r = 10.03%. If we can make more that 10.03% interest on our investments we should be able to do it, so the stock market will have to do slightly better than 10% for our child to go to Stanford. Just to double check I ran:

 V=1e4;for cnt=2:18,V=V1.1013+1e4;end,V=V.8 + 1.8e5*. V =

which is (almost) what we want. Roundoff in this last computation can onlyaffect V in its last figures, because V is computed bymultiplying and adding positive numbers, so a floating point error bound will turn out to be O(V · macheps). Note that all the coeffients of the polynomial we wanted to solve are positive except the constant term, which is negative, which means that the slope is positive for positive arguments, and p(0) < 0 so there must be a unique positive real root, which is what we want.

  1. Consider the following system of two simultaneous equations in two unknowns x and y:

f 1 (x, y) = x^2 + a · y^2 − 1 = 0 f 2 (x, y) = (x − 1)^2 + y^2 − 1 = 0

where a is a parameter.

Part 1. Solve the equations explicitlybyhand. Show that for all but a finite number of (complex) values of a, there are four (possiblycomplex) solutions ( x, y), but for this finite set of a’s, there are fewer solutions. Exhibit all solutions, and the finite set of a’s, explicitly. Four is the upper bound on the number of solutions given byBezout’s theorem as described in class

1 − (x − 1)^2 since we might have a = 0:

r 1 =

a +

a^2 − a + 1 a − 1

a +

a^2 − a + 1 a − 1

r 2 =

a +

a^2 − a + 1 a − 1

a +

a^2 − a + 1 a − 1

r 3 =

a −

a^2 − a + 1 a − 1

a −

a^2 − a + 1 a − 1

r 4 =

a −

a^2 − a + 1 a − 1

a −

a^2 − a + 1 a − 1

Part 2. Write down two explicit formulas for Newton iteration for this system. First, write it in the form (^) [ xi+ yi+

]

[

xi yi

]

− J−^1 ·

[

x^2 i + a · y^2 i − 1 (xi − 1)^2 + y^2 i − 1

]

where you explicitly exhibit the Jacobian J and its inverse J−^1. Second, evaluate this ex- pression explicitly, i.e. multiply it out and simplify. Answer: First we explicitlycalculate J and J−^1

J = 2

x ay x − 1 y

|J| = 4 y[x − ax + a]

J−^1 =

|J|

y −ay 1 − x x

2 y[x − ax + a]

y −ay 1 − x x

so that : ( xi+ yi+

xi yi

2 yi[xi − axi + a]

yi −ayi 1 − xi xi

x^2 i + ay^2 i − 1 (xi − 1)^2 + y i^2 − 1

Multiplying out and simplifying we get:

xi+1 = xi 2

1 − axi 2(xi − axi + a)

yi+1 =

yi 2

x^2 i − xi + 1 2 yi(xi − axi + a)

Part 3. Using these formulas, write a (veryshort) Matlab program to implement Newton iteration just for this example. It need onlyimplement one step, i.e. not test test convergence, so that you can just run it ”by hand” and look at the iterates to determine convergence. Thus it need onlybe a few lines long at most.

  1. Tryit for each of the finite values of a that onlyhave two solutions, and starting guesses equal to the true solutions times (1+rand(1)/100), i.e. change the true solution byabout 1%. How manysteps does it take to converge to machine precision? Do the number of correct digits roughlydouble at each step?
  2. Tryit for 3 random complex choices of a (=randn(1)+sqrt(-1)*randn(1)), and again take the true solutions, perturb them randomlyby1%, and see if Newton converges quadratically.

Answer: The following short program works (using 2-by-1 column vectors):

function [u1] = f1f2Newton(u0,a)

x0 = u0(1); y0 = u0(2); x1 = x0./2 + (1 - a.x0)./(2.(x0 - a.x0 + a)); y1 = y0./2 + (x0^2 -x0+1)/(2.y0.(x0 - a.x0 + a)); u1 = [x1; y1];

  1. When we onlyhave two solutions, two cases:

Case a = 1 The true solutions are

r 1 = (5. 000000000000000 e − 01 , 8. 660254037844386 e − 01) r 2 = (5. 000000000000000 e − 01 , − 8. 660254037844386 e − 01)

Myrandom perturbations were:

r˜ 1 = (5. 022823383258417 e − 01 , 8. 661856500355939 e − 01) r˜ 2 = (5. 041070358214763 e − 01 , − 8. 698766478912214 e − 01)

The following is a list of the relative errors in the successive Newton iterations:

r iteration x error yerror 0 4.564676651683364e-03 1.850364324822745e- 1 0 3.489185770072777e- 2 0 6.087330680015810e- 3 0 0 r iteration x error yerror 0 8.214071642952625e-03 4.447033643532061e- 1 0 2.103965223123728e- 2 0 2.213289028823506e- 3 0 0

This shows that it took 3 steps in both cases to converge and that the number of digits did roughlydouble at each step. Although there seem to be multiple roots so that

Perturbed root is:

r˜ 4 = ( 9. 525902730462289 e − 01 − 1. 558144024197772 e − 01 i, − 1. 017785863530629 e + 00 + 8. 637730631122583 e − 03 i)

The following are the relative errors for each successive iteration:

iteration x error yerror 0 9.218129707448048e-03 7.382072458106622e- 1 4.058560323436797e-05 6.779658244202396e- 2 7.932815817136543e-10 2.977020893438061e- 3 1.196520692413957e-16 3.948937458207650e- 4 2.901988940035250e-17 6.867717318621998e- 5 1.297808907974276e-16 2.208974879556959e-

Newton does appear to have converged quadratically, i.e. number of correct digits doubled with each step, and it took about 3 iterations to converge.