CS 107 - Introduction to Scientific Computation Homework #9 |

**1. Retirement Investing Analysis: ** Using the Monte Carlo analysis
techniques we developed in class as a starting point, come up with a realistic
stock investment plan, making clear your assumptions, and backing your plan with
analysis. In particular, in the initial comments of `invest.m`

, describe
your assumptions of (1) work years, (2) savings rate, and (3) goal of income
replacement. You may, if desired, extend our approach in many ways,
including the addition of bond data, social security projections, non-uniform
savings rates, etc. By running `invest.m`

, the grader should be able to
reproduce the simulations, graphs, etc. that support your plan, which should be
outlined in the initial comments of `invest.m`

. This exercise is a practical
opportunity to apply Monte Carlo analysis to your (hopefully) great future
benefit! Function `invest`

should have no parameters and return
the estimated probability of success for your plan. Note: The grading submission
system will merely judge that the probability for success is valid.
Separate evaluation (i.e. reading) by the grader will be necessary to score this
problem.

**2. Pythagorean Triples: ** Exercise 8.18 with the following
modifications: In `triples.m`

, take the maximum value of *cMax* as input, rather than
assuming 10,000 as a maximum value. To avoid redundant triples, restrict
search such that *a* ≤ *b*. Return
the (*a*, *b*, *c*) triples as a *t*-by-3 matrix, where *t*
is the number of triples. Thus, each row is a triple. Organize your loops
such that these triples are sorted by *a*, then *b*. In other words,
the first column of *a *values is sorted, and if there are multiple triples
with a given *a* value, then *b* values will be sorted among these
triples. *Hint: Your triples will be sorted correctly if you loop
through values of a and b correctly.*

**3. Dot Product: **In `dotProd.m`

, use loops to create your own dot product
function that takes two equal-length vectors and returns their dot product.
If the two vectors are not of equal length, print "dotProd: input vector lengths
do not match", and return an empty list. A dot product of two vectors *
v1* and *v2* of length *n* is *v1*(1) * *v2*(1) + *v1*(2)
* *v2*(2) + ... + *v1*(*n*) * *v2*(*n*).

**4. Matrix Multiplication: **In `matMult.m`

, use loops to create your
own matrix multiplication function that takes an *m*-by-*n* matrix *
m1* and an *n*-by-*p* matrix *m2*, and returns the *m*-by-*p*
matrix *m3* resulting from the matrix multiplication of *m1* and *m2*.
If the number of columns in *m1* does not match the number of rows in *m2*,
print "matMult: input matrices are not compatible", and return an empty list.
Otherwise, return *m3*. The value at *m3*(*i*, *k*) is
the dot product of row *i* in *m1* and (transposed) column *k* in
*m2*.