Numerical Mathematics, Spring '13 (131)
mankind so long bled and suffered, we have yet gained little if we countenance a political
intolerance as despotic, as wicked, and capable of as bitter and bloody persecutions.
— Thomas Jefferson (1743-1826) in his First Inaugural Address
Homework List
✈ Jump down to 'This Week.'
(If you see a "No jsMath TeX fonts found" error box at the top of this page, click the
button in the error box.)Week 1
- Monday, Jan 14 — First day of class
Read §1.1.
Pg 12: #3, 9, 11a, 12b, 17.
- Wednesday, Jan 16
- Convert the pseudocode to Python in: Pg 14: #15.
- Use a Python loop to answer: Pg 15: #4.
- Write Python code to calculate: \[ \textbf{Mean:}\quad \mu = \frac1n \sum_{k=1}^n a_k \] \[ \textbf{Variance:}\quad \sigma^2 = \frac1{n-1} \sum_{k=1}^n (a_k - m)^2 \]
- Friday, Jan 18 - Last day to drop/add a class
❄ No class — classes before 10:00 am are cancelled due to snow ➀
¤ Read through the Python_Intro class notes.- Investigate Python's lists.
- Write variance as a Python function.
- Monday, Jan 21 —
◊ No class — Martin Luther King, Jr, Day
- Wednesday, Jan 23
¤ Defining functions with Python:- Write a function to compute:
- The area of a square.
- The area of a rectangle.
- The area of a circle.
- The length of a string is len(S), so the value of len('allen') is 5.
Write a function named right_justify that takes a string named S as a parameter and prints the string with enough leading spaces so that the last letter of the string is in column 70 of the display.
- Write a function to compute:
- Friday, Jan 25
¤ Define the following functions in Python:- s(a) that returns the sum of the values in the list a.
- gauss5(f) that returns the Gauss-5 quadrature of the integral \(\displaystyle\int_{-1}^1 f(t)\,dt\) for the function f defined outside of gauss5. Use the lists
x and w for the nodes and weights, respectively.
- Test your function with \(f(t) = \dfrac{1}{\sqrt{2\pi}}\,e^{-t^2/2}\). The integral is \(\approx 0.6826894920\).
- Recall that the Gauss-5 nodes and weights are \[ \begin{bmatrix} x_k & w_k \\ \hline -0.9061798457 & 0.2369268851 \\ -0.5384693100 & 0.4786286705 \\ 0.0 & 0.5688888889 \\ 0.5384693100 & 0.4786286705 \\ -0.9061798457 & 0.2369268851 \end{bmatrix} \] and the Gauss-5 quadrature rule is \(\operatorname{Gauss}_5(f) = \displaystyle\sum_{k=1}^5 f(x_k)\cdot w_k\).
- Write a function gauss(x,w,f) that does the quadrature with the nodes and weights of an arbitrary size, and function f as arguments. Test with the function \(f\) above and \(n=20\):
\[ \begin{bmatrix}
i & x_i & w_i \\ \hline
1 & -0.9931285991850949247861 & 0.017614007139152118312 \\
2 & -0.9639719272779137912677 & 0.040601429800386941331 \\
3 & -0.9122344282513259058678 & 0.0626720483341090635695 \\
4 & -0.8391169718222188233945 & 0.083276741576704748725 \\
5 & -0.7463319064601507926143 & 0.1019301198172404350368 \\
6 & -0.6360536807265150254528 & 0.1181945319615184173124 \\
7 & -0.5108670019508270980044 & 0.1316886384491766268985 \\
8 & -0.3737060887154195606725 & 0.1420961093183820513293 \\
9 & -0.2277858511416450780805 & 0.149172986472603746788 \\
10 & -0.0765265211334973337546 & 0.1527533871307258506981 \\
11 & 0.0765265211334973337546 & 0.152753387130725850698 \\
12 & 0.2277858511416450780805 & 0.1491729864726037467878 \\
13 & 0.3737060887154195606725 & 0.142096109318382051329 \\
14 & 0.5108670019508270980044 & 0.131688638449176626899 \\
15 & 0.6360536807265150254528 & 0.11819453196151841731 \\
16 & 0.7463319064601507926143 & 0.101930119817240435037 \\
17 & 0.8391169718222188233945 & 0.08327674157670474872 \\
18 & 0.9122344282513259058678 & 0.062672048334109063569 \\
19 & 0.9639719272779137912677 & 0.040601429800386941331 \\
20 & 0.9931285991850949247861 & 0.017614007139152118312
\end{bmatrix} \]
Gaussian-20 Nodes and Weights
- Monday, Jan 28
◊ Write Python functions to:- Calculate the \(\sin\) of a list of values using map
- Calculate the \(\sin\) of a list of values using a for loop
- Reverse a list keeping only every third entry.
- Wednesday, Jan 30
◊ Convert these Maple functions to Python:- \(\Delta\) := (n,k) \(\to\) piecewise(k<n, \(\displaystyle\sum_{j=0}^k\)(-1)\(^j\)*binomial(k,j)*a[n-j], 0):
- M := N \(\rightarrow\) Matrix(N,N, (i,j)\(\rightarrow\) \(\Delta\)(i, j-1))
- DT := (p,h) \(\rightarrow\) subs([seq(a[i]=p(i*h), i=1..degree(p(x))+2)], M(degree(p(x))+2)))
- Friday, Feb 1
❄ No class today — wind and snow again… ➁
☞ Homework: Due nextWednesday, 2/6Friday, 2/8. Either send your function to me as a text file or in an email.- Write a Python function gauss_kronrod that uses the Gauss-Kronrod 7-15 quadrature to approximate the integral
\(\displaystyle\int_{-1}^1 f(t)\,dt\) and estimates the error.
def gauss_kronrod(f):
⋮
return (approxInt, err)
- A reference to refresh your memory: Gauss–Kronrod quadrature formula.
- Write a Python function gauss_kronrod that uses the Gauss-Kronrod 7-15 quadrature to approximate the integral
\(\displaystyle\int_{-1}^1 f(t)\,dt\) and estimates the error.
- Monday, Feb 4
❄ No class today — classes before 10:00 am are cancelled ➂
- Wednesday, Feb 6
§1.2, pg 31. #1, 2, 3, 4a-d.
- Friday, Feb 8
☞ Remember: The Gauss–Kronrod Python program homework is due today
§2.2, pg 68. #17 (also add "b. with using a series."), 20, 26cd.
◊ Look at Computer Exercises #17, pg 73.
- Monday, Feb 11
§3.2, pg 101. #3, 4, 9, 17, Look at 39.
- Wednesday, Feb 13
§3.3, pg 119. #4, 10.
◊ Look at Computer Exercises #4, pg 121.
- Friday, Feb 15
§5.7, pg 200. #1, 2, 3, 7.
◊ Computer Exercises #5a, pg 204.
- Monday, Feb 11
¤ Due: Wed 2/20:
Set \( N(x) = \displaystyle\int_0^x e^{-t^2/2}\,dt \). Compare the values from Maple's int to the Python program romberg:- for \( N(1.0) \)
- for \( N(1.0) \) after substituting \( -t^2/2=\ln(u) \). Note: revised substitution (2/19/13) — this one's much easier; it doesn't require complex integration.
- Wednesday, Feb 13
§6.1, pg 227. #1, 3, Look at 8.
¤ Prepare your one-page (8.5"\(\times\)11" max) note sheet forFriday'sMonday's test.
- Friday, Feb 15
☞ ¡The test has moved to Monday! (Avoiding the potential ice storm and by a slim majority vote.)
¤ Study the Adaptive Simpson's Notes and Programs for next Wednesday.
- Monday, Feb 25
◊ ¡Test today!
- Wednesday, Feb 27
§7.1, pg 255. #3, 5, 7e.
(#7e spoiler)
- Friday, Mar 1
◊ Investigate the different pivoting methods.
- Monday, Mar 4
§7.2, pg 272. #3, 4, 6, Look at 18.
- Wednesday, Mar 6
❄ No class today — all classes are cancelled again! ➃
¤ Use your Google-Fu on- NumPy
- SciPy
- SymPy
- Friday, Mar 8
➥ Read Key Moments in the History of Numerical Analysis by Benzi
◊ Since we lost Wednesday, the "Gaussian Elimination with Partial Pivoting" Python program is now due Monday, 3/18.
- Monday, Mar 11
- Wednesday, Mar 13
- Friday, Mar 15
- Monday, Mar 18
§10.1, pg 436. #1ab, 2a, 3a, 8.
- Wednesday, Mar 20
◊ Project: (due Wednesday, March 27)- Work the Euler's Method project.
- Redo the Euler's Method project using the second order Taylor's method.
- Friday, Mar 22
◊ Project Day!
- Monday, Mar 25
◊ Project Day!
- Wednesday, Mar 27
§10.2, pg 445. #2, 6, 8.
- Friday, Mar 29
§10.2, pg 447. #2, 5.
- Monday, Apr 1
No classes — «State holiday»
- Wednesday, Apr 3
¤ Write Maple code implementing an adaptive RK45 DE numeric solver.
- Friday, Apr 5
- Finish the Maple version of the adaptive RK45 DE numeric solver.
- Test your code with the first-order IVPs below and compare your values with the exact solution:
- IVP: \(\left\{y^\prime + y = 2,\; y(0)=1 \right\}\); exact solution: \(y(x)=2-e^{-x}\)
- Stiff IVP: \(\left\{y^\prime =-100y,\; y(0)=10 \right\}\); exact solution: \(y(x)=10\,e^{-100x}\)
- IVP: \(\left\{y^\prime = \sin(x\,y)+\frac12 x - y,\; y(0)=1 \right\}\); exact solution: not this time
Use:
DEtools[DEplot](y'=sin(x\(\cdot\)y)+x/2-y, [y(x)], x=0..10, y(x)=0..4, [[y(0)=1]], linecolor=blue)
to see Maple's numeric solution.
- Monday, Apr 8
§10.3, pg 460. #9, 11.
- Wednesday, Apr 10
§11.1, pg 475. #1.
- Friday, Apr 12
◊ Predator-Prey with Euler's method and RK4 Maple worksheet.
¤ Change the Lotka-Volterra system in the predator-prey worksheet to a "Competitve Hunter" model \[ \begin{cases} x^\prime = 0.2x - 0.001 x y \\ y^\prime = 0.3 y - 0.002 x y \end{cases} \] with \(\langle x_0,y_0\rangle = \langle 100,100\rangle\) where \(x\): owls and \(y\): hawks.
- Produce plots similar to those for our predator-prey system. (You'll have to adjust plot ranges.)
- Find the equilibrium point(s).
- Describe long-term behaviour.
- Monday, Apr 15
◊ Investigate the nonlinear pendulum with the Maple worksheet.
- Wednesday, Apr 17
§11.2, pg 483. #3.
- Friday, Apr 19
◊ ¡ ☛ TEST ☚ today!
¤ Your ☛ TEST ☚ solutions are due Wednesday, Apr 24.
- Monday, Apr 22
§17.1, pg 666. #4.
- Wednesday, Apr 24
¤ Finish working your test and turn it in!
- Friday, Apr 26
◊ Set up the initial simplex tableaux for the housing project problem from class:A developer has 60 acres for a new subdivision of townhouses, single-story houses, and two-story houses. On one acre he can put 6 townhouses, 4 single-story houses, or 2 two-story houses. It costs $40,000 to build a townhouse, $50,000 for a single-story house, and $60,000 for a two-story house. He makes a profit of $15,000 on a townhouse, $18,000 on a single-story house, and $20,000 on a two-story house. He has $2,880,000 of capital available. Townhouses require 2,500 hours of labor, single-story houses require 3,000 hours of labor, and two-story houses require 4,000 hours of labor. He has 240,000 hours of labor available.
- Monday, Apr 29
¤ Try the Lego simplex problem.
- Wednesday, May 1
¤ Set up the Power Company LP problem.
¤ Set up the dual for the Power Company problem.
- Friday, May 3
◊ The ☛ Final Exam ☚
- Thursday, May 9, Noon to 2:30 pm
◊ The exam is...
“On two occasions I have been asked, ‘Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?’ ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.”
Last modified: Wednesday, 01-Feb-2023 08:32:12 EST
[an error occurred while processing this directive]