TP3 2425 Eng
TP3 2425 Eng
Objective of this TP
The goal of this practical work (TP) is to implement two methods for the nu-
merical resolution of the equation f (x) = 0 and compare these methods.
1. Implementation
Write a function iterativemethod1(f, a, b, epsilon, Nmax) that returns
the approximate zero x∗ of a continuous, strictly monotonic function f on [a, b]
using the bisection method and also returns the number of iterations.
Function Arguments:
• f: The function to solve.
• a, b: Real numbers such that a < b.
• epsilon: A real number ϵ > 0.
• Nmax: Maximum number of iterations.
Expected Result: The function should return the approximate value of
x∗ with a precision of ϵ and the number of iterations. If f (a) · f (b) > 0, the
function should return an error message indicating that f (a) and f (b) do not
have opposite signs.
The stopping criterion is |bn − an | ≤ ϵ.
2. Example Function
Consider the continuous function on [1, 2]:
f (x) = ln(1 + x2 ) − sin(x)
Graphically justify that the equation f (x) = 0 admits a unique solution in [1, 2].
Test the function with ϵ = 10−5 and N max = 20.
1
2 Iterative Method 2
We consider a continuous function f on [a, b] such that f (a) ̸= f (b).
The numerical approximation of the root of the equation f (x) = 0 is obtained
using the following iterative scheme:
b−a
(M I)n : xn+1 = xn − f (xn ), x0 ∈ [a, b]
f (b) − f (a)
1. Implementation
Write a function iterativemethod2(a, b, x0, f, epsilon) that returns two
lists: one containing the iterates x = [x0 , x1 , x2 , . . .] and the other containing
y = [f (x0 ), f (x1 ), f (x2 ), . . .].
2. Example
Take x0 = 2 and ϵ = 10−2 .