====== Differences ====== This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
gibson:teaching:spring-2015:math445:lab6 [2015/02/18 19:09] gibson created |
gibson:teaching:spring-2015:math445:lab6 [2015/02/25 09:03] (current) spears |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Math 445 Lab 6 ====== | ====== Math 445 Lab 6 ====== | ||
- | **Problem 1:** Find all solutions of the equation $x^4 - 2x^3 -3x^2 + 5x - 4 =0$ in the following steps. Define a function $f(x) = x^4 - 2x^3 -3x^2 + 5x - 4$ using Matlab's anonymous function syntax. Define a vector x of gridpoints over some appropriate range using Matlab's ''linspace'' function. Plot $f(x)$ versus x and note the approximate values of x where $f(x) = 0$. Then use these approximate zeros of $f$ as initial guesses for calls to Matlab's ''fsolve'' function to find precise solutions. Plug each solution back into $f(x)$ to show that ''fsolve'' in fact produces numerically accurate solutions. | + | **Problem 1:** Find all solutions of the equation $x^4 - 2x^3 -3x^2 + 5x - 4 =0$ in the following steps. Define a function $f(x) = x^4 - 2x^3 -3x^2 + 5x - 4$ using Matlab's anonymous function syntax. Define a vector x of gridpoints over some appropriate range using Matlab's ''linspace'' function. Plot $f(x)$ versus x and note the approximate values of x where $f(x) = 0$. Then find precise solutions by calling Matlab's ''fsolve'' function with the approximate solutions as initial guesses. Plug each precise solution back into $f(x)$ to show that ''fsolve'' in fact produces numerically accurate solutions. |
- | **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 11: | 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 | + | ---- |
- | **Problem 4:** Write a function ''mymean(x)'' that compute the mean value of the elements in the input vector ''x'' according to the formula | + | 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 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=N}^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 5:** 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=N}^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*} | ||
where N is the number of elements in the vector ''x'' and $\bar{x}$ is the mean of ''x''. Figure out a good way to test your function and test it. | where N is the number of elements in the vector ''x'' and $\bar{x}$ is the mean of ''x''. Figure out a good way to test your function and test it. | ||
- | **Problem 6:** Write a function ''mygeomean(x)'' that computes the geometric mean of the elements in the input vector ''x'' according to the formula | + | **Problem 5:** Write a function ''mygeomean(x)'' that computes the geometric mean of the elements in the input vector ''x'' according to the formula |
\begin{eqnarray*} | \begin{eqnarray*} | ||
- | \text{geomean}(x) = \sqrt[N]{\prod_{i=N}^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. | ||
| |