

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Math 128A, Spring 2007
Programming Assignment 1 Solution
The answers to the numbered questions are here. The code to generate the tables and plots can be found in a separate file.
f (x) = sin(x)/x^2 โ cos(x)/x
and generated the following data
run 1 run 2 run 3 p 0 3.0000 7.0000 1.0000e- p 1 3.1000 7.1000 9.0000e- p 2 4.8147 7.7642 -9.5880e- p 3 4.5333 7.7262 8.0948e- p 4 4.4898 7.7252 -6.8134e- p 5 4.4934 7. p 6 4.4934 7. p 7 4. p 8 4.
The first two positive roots of f (x) are displayed. When the iteration starts close to zero, it converges to zero. This is expected, since the above formulation of f (x) can be extended by letting f (0) = 0, yielding a continuously differentiable function with a simple root at 0.
p(x) = x^5 โ 34 + 2x^3 + 2x^2 โ 3 x + 1 = (x โ 1)^4 (x + 1)
the roots are ยฑ1. Here is the data from two runs of the secant method converging to the two roots:
i pi i i+1/i 0 0.5000 5.0000e-01 8.0000e- 1 0.6000 4.0000e-01 8.0602e- 2 0.6776 3.2241e-01 8.0895e- 3 0.7392 2.6081e-01 8.1143e- 4 0.7884 2.1163e-01 8.1308e- 5 0.8279 1.7207e-01 8.1438e- 6 0.8599 1.4013e-01 8.1536e- .. .
41 0.9999 1.2709e-04 8.1917e- 42 0.9999 1.0411e-04 8.1917e- 43 0.9999 8.5280e-
and i pi i i+1/ฯi 0 -1.5000 5.0000e-01 1.2278e+ 1 -1.4000 4.0000e-01 8.2806e- 2 -1.1880 1.8801e-01 1.2862e+ 3 -1.0861 8.6083e-02 1.2721e+ 4 -1.0241 2.4054e-02 1.5134e+ 5 -1.0036 3.6365e-03 1.4962e+ 6 -1.0002 1.6907e-04 1.5518e+ 7 -1.0000 1.2238e-06 1.5241e+ 8 -1.0000 4.1375e-10 1.6899e+ 9 -1.0000 1.1102e-15 0.0000e+ 10 -1.0000 0. where ฯ = (1 +
According to the data, the secant method converges linearly to 1 and with rate ฯ to โ1 (note the near constant ratios in the third columns). This is exactly what was expected, given that 1 is a multiple root while โ1 is simple. The output for โ1 is more accurate (in fact, exact in floating-point). This is because f (x) is very flat near 1, so the criterion |f (pi)| < ytol terminates the iteration early.
1.85 1.9 1.95 2 2.05 2.1 2.
โ 6
โ 4
โ 2
0
2
4
6
8
x 10^ โ^5
x axis (x โ 2)^5 (x โ 2)^5 + 10โ^6 x^3
The secant method computes the new root as r = 1.9071. The ratio of change in root to change in coefficient is 9. 2943 ร 104 , which is enormous.