Docsity

Math 128A, Spring 2007: Programming Assignment 1 - Secant Method and Root Convergence, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
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.
1. I ran my secant method implementation with
f(x) = sin(x)/x2โˆ’cos(x)/x
and generated the following data
run 1 run 2 run 3
p03.0000 7.0000 1.0000e-01
p13.1000 7.1000 9.0000e-01
p24.8147 7.7642 -9.5880e-03
p34.5333 7.7262 8.0948e-04
p44.4898 7.7252 -6.8134e-09
p54.4934 7.7253
p64.4934 7.7253
p74.4934
p84.4934
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.
2. Since
p(x) = x5โˆ’34+ 2x3+ 2x2โˆ’3x+ 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-01
1 0.6000 4.0000e-01 8.0602e-01
2 0.6776 3.2241e-01 8.0895e-01
3 0.7392 2.6081e-01 8.1143e-01
4 0.7884 2.1163e-01 8.1308e-01
5 0.8279 1.7207e-01 8.1438e-01
6 0.8599 1.4013e-01 8.1536e-01
.
.
..
.
..
.
..
.
.
41 0.9999 1.2709e-04 8.1917e-01
42 0.9999 1.0411e-04 8.1917e-01
43 0.9999 8.5280e-05
1
pf3

Partial preview of the text

Download Math 128A, Spring 2007: Programming Assignment 1 - Secant Method and Root Convergence and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

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.

  1. I ran my secant method implementation with

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.

  1. Since

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. In the neighborhood of x = 2, adding 10โˆ’^6 x^3 to p(x) = (x โˆ’ 2)^5 has about the same effect as adding 2 ร— 10 โˆ’^6. Thus we expect the new polynomial to have exactly one real root, which is simple, slightly to the left of 2. Here is a graph of the situation:

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.