User Tools

Site Tools


gibson:teaching:fall-2014:math445:hw5

This is an old revision of the document!


Math 445 HW5

Main concept for this homework: the for loop.

1. Write a function mymean that uses a for loop to compute the mean of the elements of its input vector. Test that it's correct by comparing to Matlab's built-in mean function on a random vector.

2. Write a function mystd that uses a for loop to computes the standard deviation of the elements of its input vector. Test by comparison to Matlab's built-in std function on a random vector.

3. Write a script that produces a 10 x 10 multiplication table whose first three lines are

  1   2   3   4   5   6   7   8   9  10
  2   4   6   8  10  12  14  16  18  20
  3   6   9  12  15  18  21  24  27  30
  .
  .
  .
 

Try to get the output in exactly this form.

4. Write a function y = matvecmult(A,x) that uses nested for loops to compute the matrix-vector product y = Ax according to the formula

\begin{eqnarray*}
y_i = \sum_{j=1}^N A_{ij} x_j
\end{eqnarray*}

where N is the number of columns of A. Be sure to check for compatibility between A and x. For an M x N matrix A, x must be an N-dimensional column vector, and y will be an M-dimensional column vector. If A and x do not have compatible dimensions, print an error message and return 0-dimensional vector (a null vector).

5. Write a function C = matmatmult(A,B) that uses nested for loops to compute the matrix-vector product C=AB according to the formula

\begin{eqnarray*}
C_{ij} = \sum_{k=1}^N A_{ik} C_{kj}
\end{eqnarray*}

where N is the number of columns of A. If A is M x N and B is N x P, then C is M x P. If A and B do not have compatible dimensions, print an error message and return a 0 x 0 matrix.

gibson/teaching/fall-2014/math445/hw5.1413229734.txt.gz · Last modified: 2014/10/13 12:48 by gibson