User Tools

Site Tools


gibson:teaching:spring-2016:math445:lab5

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gibson:teaching:spring-2016:math445:lab5 [2016/02/15 10:28]
gibson
gibson:teaching:spring-2016:math445:lab5 [2016/02/18 08:36] (current)
gibson
Line 1: Line 1:
 ====== Math 445 lab 5: programming basics ====== ====== Math 445 lab 5: programming basics ======
 +
 +
 +Matlab vocabulary for this lab
 +<​code>​
 +  for
 +  fprintf
 +  function
 +  mean
 +  std
 +  *
 +  length
 +  size
 +  rand
 +  randn
 +</​code>​
  
 **Problem 1:** Write a **for** loop that will print statements of the form **Problem 1:** Write a **for** loop that will print statements of the form
Line 12: Line 27:
 ---- ----
  
-**Problem 2:** If $F$ is a temperature in Farenheit, then $C = \frac{5}{9}(F-32)$ is the same temperature in Celsius. Write a function ''​farenheit2celsius''​ that takes a Celsius ​temperature as input, converts it to Celsius, prints a statement of the form ''​20 Farenheit is -6.6667 Celsius.'',​ and returns the Celsius value as its output. ​+**Problem 2:** If $F$ is a temperature in Farenheit, then $C = \frac{5}{9}(F-32)$ is the same temperature in Celsius. Write a function ''​farenheit2celsius''​ that takes a Farenheit ​temperature as input, converts it to Celsius, prints a statement of the form ''​20 Farenheit is -6.6667 Celsius.'',​ and returns the Celsius value as its output. ​
  
 ---- ----
Line 25: Line 40:
 for Farenheit temperatures from -10 to 100, in steps of 10. for Farenheit temperatures from -10 to 100, in steps of 10.
  
 +Challenge: Get the text to line up nicely using field-width specifiers in fprintf!
 ---- ----
  
-**Problem 4:** Write a function ''​average''​ that takes an input vector $x$ and computes ​the average (mean) value of its elements, according to the formula+**Problem 4:** Write a function ''​average''​ that takes an input vector $x$ and returns as output ​the average (mean) value of its elements, according to the formula
  
 \begin{equation*} \begin{equation*}
Line 38: Line 54:
 ---- ----
  
-**Problem 5:** Write a function ''​deviation''​ that takes an input vector $x$ and computes ​the standard deviation of its elements, according to the formula+**Problem 5:** Write a function ''​deviation''​ that takes an input vector $x$ and returns ​the standard deviation of its elements, according to the formula
  
 \begin{equation*} \begin{equation*}
-\text{deviation}(x) = \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i - \bar{X})^2}+\text{deviation}(x) = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \bar{X})^2}
 \end{equation*} \end{equation*}
  
Line 49: Line 65:
 ---- ----
  
-**Problem ​5:** The formula for matrix-vector multiplication $y = Ax$ is +**Problem ​6:** The formula for matrix-vector multiplication $y = Ax$ is 
  
 <​latex>​ <​latex>​
Line 55: Line 71:
 </​latex>​ </​latex>​
  
-In this formula, $A$ is an $m \times n$ matrix, $x$ is an $n$-dimensional column vector, and $y$ is an $m$-dimesional ​column vector.+In this formula, $A$ is an $m \times n$ matrix, $x$ is an $n$-dimensional column vector, and $y$ is an $m$-dimensional ​column vector.
  
 Write a function ''​matvecmult''​ that takes a matrix $A$ and a vector $x$ as inputs, computes $y = Ax$ according to that formula, and returns the vector $y$. Compare your ''​matvecmult''​ to Matlab'​s built-in matrix-vector multiplication operator ''​*''​ on a random $4 \times 4$ matrix and a random 4d column vector. Write a function ''​matvecmult''​ that takes a matrix $A$ and a vector $x$ as inputs, computes $y = Ax$ according to that formula, and returns the vector $y$. Compare your ''​matvecmult''​ to Matlab'​s built-in matrix-vector multiplication operator ''​*''​ on a random $4 \times 4$ matrix and a random 4d column vector.
  
-...to be continued...+---- 
 + 
 +**Problem 7:** The formula for matrix-matrix multiplication $C = AB$ of an $m \times n$ matrix $A$ and an, $n \times p$ matrix $B$ is 
 + 
 +<​latex>​ 
 +C_{i,j} = \sum_{k=1}^n A_{ik} B_{k,j} \quad \text{ for } i = 1,\dots,m, \text{ and } j = 1,​\dots,​p,​ 
 +</​latex>​ 
 + 
 +The product $C = AB$ is an $m \times p$ matrix. 
 + 
 +Write a function ''​matmatmult''​ that takes a matrix $A$ and a vector $x$ as inputs, computes $C = AB$ according to that formula, and returns the matrix $C$Compare your ''​matmatmult'' ​to Matlab'​s built-in matrix-vector multiplication operator ''​*''​ on a random $4 \times 3$ matrix $A$ and a random $3 \times 5$ matrix B. 
gibson/teaching/spring-2016/math445/lab5.1455560916.txt.gz · Last modified: 2016/02/15 10:28 by gibson