====== Differences ====== This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
gibson:teaching:spring-2015:math445:hw2 [2015/02/15 12:33] gibson created |
gibson:teaching:spring-2015:math445:hw2 [2015/02/16 06:41] (current) gibson |
||
---|---|---|---|
Line 3: | Line 3: | ||
Helpful Matlab functions | Helpful Matlab functions | ||
- | sum, any, all, linspace | + | sum, linspace, colon syntax, dot syntax |
- | plot, semilogy, semilogx, xlabel, ylabel, legend, axis, | + | * (mat-vec mult), \, norm, |
+ | plot, semilogy, semilogx, loglog, xlabel, ylabel, legend, axis, grid, axis | ||
hist, randn | hist, randn | ||
+ | exp | ||
**Problem 1:** Write a Matlab expression that sums the first N of each series and evaluate it for N=100. | **Problem 1:** Write a Matlab expression that sums the first N of each series and evaluate it for N=100. | ||
Line 15: | Line 17: | ||
(e) 1/2 - 2/3 + 3/4 - 4/5 + ...\\ | (e) 1/2 - 2/3 + 3/4 - 4/5 + ...\\ | ||
| | ||
- | **Problems 2,3 and 4:** | + | **Problem 2:** A theater has a seating capacity of 900 and charges %%$%%2.50 for children, %%$%%4 for students, and %%$%%5.50 for adults. At a certain screening with full attendance, there were half as many adults as children and students combined. The total money brought in was %%$%%3825. How many children, students, and adults attended the show? Write out the equations in algebra, translate to a matrix-vector $Ax=b$ problem, and solve that numerically in Matlab. Show that your answer is correct to floating-point accuracy by computing $\| Ax-b\|$ (the norm of difference between the left and right-hand sides of the equation $Ax=b$). |
- | Test that your expression gives the right answer on a good set of test vectors. | + | |
- | But please turn in just the general Matlab expression, not the tests. | + | |
+ | **Problems 3-9:** Turn in the Matlab code and the figures. Always label the figures appropriately, using ''title'', ''xlabel'' and either ''ylabel'' or ''legend''. The figures should be titled "Problem 5", etc. Read ''help'' for the following functions and then experiment with them to see how they affect the plot. | ||
- | **Problem 2:** Given vectors x,y of the same length, write expression that has value | + | figure, clf, hold on, hold off |
- | true (1) if **each** component of x is greater than the corresponding | + | grid, xticks, yticks |
- | component of y, false otherwise. | + | axis([xmin xmax ymin ymax), axis equal, axis square |
+ | randn, hist | ||
- | **Problem 3:** Given vectors x,y of the same length, write expression that has value | + | **Problem 3:** Plot sin(x) versus x for 100 evenly space points in x from 0 to 2pi, using a solid blue line. |
- | true (1) if **any** component of x is greater than the corresponding | + | |
- | component of y, false otherwise. | + | |
- | **Problem 4:** Given vector x, write expression that has value true (1) if the elements of x | + | **Problem 4:** Plot $y = 5x^2 - 4x - 3$ for 40 evenly space points in x from -2 to 2, using a red line and a circle on each data point. Superimpose an x,y grid on the plot. |
- | are sorted in increasing order (that is, if no element is less than the previous element) and | + | |
- | false otherwise. | + | |
- | **Problems 5-11:** Turn in the Matlab code and the figures. Always label the figures appropriately, using ''title'', ''xlabel'' and either ''ylabel'' or ''legend''. The figures should be titled "Problem 5", etc. Read ''help'' for the following functions and then experiment with them to see how they affect the plot. | + | **Problem 5:** Make a plot of the unit circle. Make sure it's closed --no gap! Hint: use ''linspace'' to specify a range of angles, then ''cos'' and ''sin'' to produce vectors of the x,y coordinates of points on the unit circle. |
- | figure, clf, hold on, hold off | + | **Problem 6:** Plot $10^{3x}$ for 100 points in x evenly space between -2 and 5. Choose the most appropriate plotting function. Hint: it ain't ''plot''! |
- | grid, xticks, yticks | + | |
- | axis([xmin xmax ymin ymax), axis equal, axis square | + | **Problem 7:** Plot $3 x^5$ for 100 points in x evenly space between 1 and 4. Choose the most appropriate plotting function. Again, it ain't ''plot''! |
- | **Problem 5:** Plot sin(x) versus x for 100 evenly space points in x from 0 to 2pi, using a solid blue line. | + | **Problem 8:** Make a histogram of 1000 random numbers from a normal (Gaussian) distribution. Use Matlab's ''hist'' and ''randn'' functions. |
- | **Problem 6:** Plot sin(x) in red, cos(x) in green, over same x as problem 5. Use 'legend' to indicate which function is shown in which color. | + | **Problem 9:** Chemicals A and B combine in reaction to form chemical C. The rate of production of C is proportional to the amount of A and the amount of C present at any given time: $dC/dt = \alpha A(t) B(t)$. 2 gm of A combine with 1 gm of B to form 3 gm of C. At the start of the reaction there are 40 gm A, 50 gm B, and 0 gm C. After 5 minutes there are 10 gm of C. |
- | **Problem 7:** Plot $y = 5x^2 - 4x - 3$ for 40 evenly space points in x from -2 to 2, using a red line and a circle on each data point. Superimpose an x,y grid on the plot. | + | This is a problem in differential equations. If you take MATH 527 you will learn how to solve this problem and determine the amounts of A, B, and C (in grams) as a function of time t (in minutes). These functions are |
+ | |||
+ | \begin{eqnarray*} | ||
+ | C(t) &= 300 (e^{0.0227 t}-1)/(5e^{0.0227 t} - 2) | ||
+ | \end{eqnarray*} | ||
+ | \begin{eqnarray*} | ||
+ | A(t) &= 40 - 2/3 \; C(t) | ||
+ | \end{eqnarray*} | ||
+ | \begin{eqnarray*} | ||
+ | B(t) &= 50 - 1/3 \; C(t) | ||
+ | \end{eqnarray*} | ||
+ | |||
+ | Make a plot of A, B, and C versus t for t between 0 and two hours. Label the horizontal axis and indicate which curve is which with a legend. | ||
+ | |||
+ | **Problem 10:** Use the graph from problem 9 to answer the following questions about the reaction. You might need to refine your plot and zoom in answer some of these. | ||
+ | |||
+ | (a) How much A,B, and C are present after one hour?\\ | ||
+ | (b) How much C is eventually produced?\\ | ||
+ | %%(c)%% Are A and B fully depleted in the long-term limit? If not, how much of each are left?\\ | ||
+ | (d) Does your answer to %%(c)%% make sense, given the problem description? Explain.\\ | ||
+ | (e) How long does it take for the reaction to reach 95% completion? | ||
- | **Problem 8:** Make a plot of the unit circle. Make sure it's closed --no gap! Hint: use ''linspace'' to specify a range of angles, then ''cos'' and ''sin'' to produce vectors of the x,y coordinates of points on the unit circle. | ||
- | **Problem 9:** Plot $10^{3x}$ for 100 points x evenly space between -2 and 5. Choose the most | ||
- | appropriate plotting function. Hint: it ain't ''plot''! | ||
- | | ||
- | **Problem 10:** Plot $3 x^5$ for 100 points x evenly space between 1 and 4. Choose the most | ||
- | appropriate plotting function. Again, it ain't ''plot''! | ||
- | **Problem 11:** Make a histogram of 1000 random numbers from a normal (Gaussian) distribution. Use Matlab's ''hist'' and ''randn'' functions. | ||