====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:spring-2015:math445:lab6 [2015/02/18 19:14] gibson |
gibson:teaching:spring-2015:math445:lab6 [2015/02/25 09:03] (current) spears |
||
---|---|---|---|
Line 5: | Line 5: | ||
---- | ---- | ||
- | **Problem 2:** Write an ''f2c(f)'' and a ''c2f(c)'' function that convert Farenheit tempeatures to Celsius and vice versa. Each function should print a statement of the form | + | **Problem 2:** Write an ''f2c(f)'' and a ''c2f%%(c)%%'' function that convert Farenheit temperatures to Celsius and vice versa. Each function should print a statement of the form |
For input 32 F, the output is 0 C | For input 32 F, the output is 0 C | ||
Line 13: | Line 13: | ||
For input 100 C, the output is 212 F | For input 100 C, the output is 212 F | ||
| | ||
- | and then return the correct converted temperature. Write the functions in files ''f2c.m'' and ''c2f.m''. Make sure the functions are correct by checking that the above equivalent termperatures are converted correctly, and by computing ''f2c(c2f(x))'' and ''c2f(f2c(x))'' for a variety of values of ''x''. | + | and then return the correct converted temperature. Write the functions in files ''f2c.m'' and ''c2f.m''. Make sure the functions are correct by checking that the above equivalent temperatures are converted correctly, and by computing ''f2c(c2f(x))'' and ''c2f(f2c(x))'' for a variety of values of ''x''. |
---- | ---- | ||
- | Note: problems 3,4, and 5 use names like ''mymean''to avoid conflicts with similiar built-in Matlab functions. | + | Note: problems 3,4, and 5 use names like ''mymean'' to avoid conflicts with similar built-in Matlab functions. |
- | **Problem 3:** Write a function ''mymean(x)'' that compute the mean value of the elements in the input vector ''x'' according to the formula | + | **Problem 3:** Write a function ''mymean(x)'' that computes the mean value of the elements in the input vector ''x'' according to the formula |
\begin{eqnarray*} | \begin{eqnarray*} | ||
- | \text{mean}(x) = \frac{1}{N} \sum_{i=0}^N x_i | + | \text{mean}(x) = \frac{1}{N} \sum_{i=1}^N x_i |
\end{eqnarray*} | \end{eqnarray*} | ||
- | where N is the number of elements in the vector ''x''. Compute this sum with a ''for'' loop. Figure out a good way to test your function and test it. | + | where N is the number of elements. Compute this sum with a ''for'' loop. Figure out a good way to test your function and test it. |
**Problem 4:** Write a function ''mystd(x)'' that computes the standard deviation of the elements in the input vector ''x'' according to the formula | **Problem 4:** Write a function ''mystd(x)'' that computes the standard deviation of the elements in the input vector ''x'' according to the formula | ||
\begin{eqnarray*} | \begin{eqnarray*} | ||
- | \text{std}(x) = \sqrt{\frac{1}{N} \sum_{i=0}^N (x_i - \bar{x})^2} | + | \text{std}(x) = \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i - \bar{x})^2} |
\end{eqnarray*} | \end{eqnarray*} | ||
Line 37: | Line 37: | ||
\begin{eqnarray*} | \begin{eqnarray*} | ||
- | \text{geomean}(x) = \sqrt[N]{\prod_{i=0}^N |x_i|} | + | \text{geomean}(x) = \sqrt[N]{\prod_{i=1}^N |x_i|} |
\end{eqnarray*} | \end{eqnarray*} | ||
+ | Figure out a good way to test your function and test it. | ||
| |