Docsity

Homework 2 Solutions | Applied Numerical Methods | MATH 151A, Assignments of Mathematics

Toggle sidebar
bg1
Homework 2 Solutions
Igor Yanovsky (Math 151A TA)
Problem 1: Show that the iteration equation for the Secant method can be written in
the following form:
pn=f(pn−1)pn−2−f(pn−2)pn−1
f(pn−1)−f(pn−2).
Solution: The Secant iteration is defined as
pn=pn−1−f(pn−1)(pn−1−pn−2)
f(pn−1)−f(pn−2).
We have
pn=pn−1−f(pn−1)(pn−1−pn−2)
f(pn−1)−f(pn−2)
=(f(pn−1)−f(pn−2))pn−1−f(pn−1)(pn−1−pn−2)
f(pn−1)−f(pn−2)
=f(pn−1)pn−2−f(pn−2)pn−1
f(pn−1)−f(pn−2).X
Problem 2: Let f(x)=−x3−cos x. With p0=−1 and p1= 0, find p3using the
Secant method.
Solution: The Secant iteration is defined as
pn=pn−1−f(pn−1)(pn−1−pn−2)
f(pn−1)−f(pn−2).
We have
p2=p1−f(p1)(p1−p0)
f(p1)−f(p0)=0−f(0)(0 + 1)
f(0) −f(−1) =−f(0)
f(0) −f(−1)
=−−cos 0
−cos 0 −(−(−1)3−cos(−1)) =−−1
−1−(1 −cos(−1))
=1
−2 + cos(−1) =1
−2+0.5403 =−0.6851.
p3=p2−f(p2)(p2−p1)
f(p2)−f(p1)=−0.6851 −f(−0.6851)(−0.6851 −0)
f(−0.6851) −f(0)
=−0.6851 −−0.6851(−(−0.6851)3−cos(−0.6851))
−(−0.6851)3−cos(−0.6851) + cos(0)
=−1.252.X
Note that f(−1.252) = 1.649, which is far from 0. We need to make three more iterations
to get reasonably close to the answer.
1
pf3

Partial preview of the text

Download Homework 2 Solutions | Applied Numerical Methods | MATH 151A and more Assignments Mathematics in PDF only on Docsity!

Homework 2 Solutions

Igor Yanovsky (Math 151A TA)

Problem 1: Show that the iteration equation for the Secant method can be written in the following form:

pn = f (pn− 1 )pn− 2 − f (pn− 2 )pn− 1 f (pn− 1 ) − f (pn− 2 )

Solution: The Secant iteration is defined as

pn = pn− 1 −

f (pn− 1 )(pn− 1 − pn− 2 ) f (pn− 1 ) − f (pn− 2 )

We have

pn = pn− 1 − f (pn− 1 )(pn− 1 − pn− 2 ) f (pn− 1 ) − f (pn− 2 )

=

(f (pn− 1 ) − f (pn− 2 ))pn− 1 − f (pn− 1 )(pn− 1 − pn− 2 ) f (pn− 1 ) − f (pn− 2 )

= f (pn− 1 )pn− 2 − f (pn− 2 )pn− 1 f (pn− 1 ) − f (pn− 2 )

. X

Problem 2: Let f (x) = −x^3 − cos x. With p 0 = −1 and p 1 = 0, find p 3 using the Secant method.

Solution: The Secant iteration is defined as

pn = pn− 1 − f (pn− 1 )(pn− 1 − pn− 2 ) f (pn− 1 ) − f (pn− 2 )

We have

p 2 = p 1 −

f (p 1 )(p 1 − p 0 ) f (p 1 ) − f (p 0 )

f (0)(0 + 1) f (0) − f (−1)

f (0) f (0) − f (−1) = − − cos 0 − cos 0 − (−(−1)^3 − cos(−1))

− 1 − (1 − cos(−1))

−2 + cos(−1)

p 3 = p 2 −

f (p 2 )(p 2 − p 1 ) f (p 2 ) − f (p 1 )

f (− 0 .6851)(− 0. 6851 − 0) f (− 0 .6851) − f (0)

= − 0. 6851 − − 0 .6851(−(− 0 .6851)^3 − cos(− 0 .6851)) −(− 0 .6851)^3 − cos(− 0 .6851) + cos(0) = − 1. 252. X

Note that f (− 1 .252) = 1.649, which is far from 0. We need to make three more iterations to get reasonably close to the answer.

Computational Problem: The function f (x) = tan(πx) − 6 has a zero at arctan(6) π ≈ 0 .447431543. Use ten iterations of each of the following methods to approximate this root. Which method is most successful? a) Bisection method with initial interval [0, 1]. b) Secant method with p 0 = 0.4 and p 1 = 0.48. c) Newton’s method with p 0 = 0.4.

Solution: The plot of the function f (x) = tan(πx) − 6 is shown below. It is important to note that f has several roots on the interval [0, 5]. This interval was considered in the earlier version of this homework. Even though you had to use the new version of the homework assignment, I will at least mention what happens if the old initial guesses were used.

a) Note that since f has several roots in [0, 5], the bisection method converges to a differ- ent root in this interval. Therefore, it would be a better idea to choose the interval to be [0, 1]. For such case, we have the following results:

iteration # 1 , p = 2.50000000e-001, |p−ptrue| = 1.97431543e-001, f(p) = -5.00000000e+ iteration # 2 , p = 3.75000000e-001, |p−ptrue| = 7.24315433e-002, f(p) = -3.58578644e+ iteration # 3 , p = 4.37500000e-001, |p−ptrue| = 9.93154329e-003, f(p) = -9.72660508e- iteration # 4 , p = 4.68750000e-001, |p−ptrue| = 2.13184567e-002, f(p) = 4.15317039e+ iteration # 5 , p = 4.53125000e-001, |p − ptrue| = 5.69345671e-003, f(p) = 7.41452405e- iteration # 6 , p = 4.45312500e-001, |p−ptrue| = 2.11904329e-003, f(p) = -2.36857995e- iteration # 7 , p = 4.49218750e-001, |p − ptrue| = 1.78720671e-003, f(p) = 2.14987771e- iteration # 8 , p = 4.47265625e-001, |p−ptrue| = 1.65918289e-004, f(p) = -1.92260366e- iteration # 9 , p = 4.48242188e-001, |p − ptrue| = 8.10644211e-004, f(p) = 9.56908037e- iteration #10, p = 4.47753906e-001, |p − ptrue| = 3.22362961e-004, f(p) = 3.77002196e- iteration #11, p = 4.47509766e-001, |p − ptrue| = 7.82223363e-005, f(p) = 9.10590697e-