@@ -202,6 +202,69 @@ def pegasus(f, a, b, toler, iter_max):
202202 return [root , i , converged ]
203203
204204
205+ def muller (f , a , c , toler , iter_max ):
206+ """Calculate the root of an equation by the Muller method.
207+
208+ Args:
209+ f: function f(x).
210+ a: lower limit.
211+ c: upper limit.
212+ toler: tolerance (stopping criterion).
213+ iter_max: maximum number of iterations (stopping criterion).
214+
215+ Returns:
216+ root: root value.
217+ iter: number of iterations used by the method.
218+ converged: flag to indicate if the root was found.
219+ """
220+ b = (a + c ) / 2
221+ fa = f (a )
222+ fb = f (b )
223+ fc = f (c )
224+ x = b
225+ fx = fb
226+ delta_x = c - a
227+
228+ converged = False
229+ for i in range (0 , iter_max + 1 ):
230+ h1 = c - b
231+ h2 = b - a
232+ r = h1 / h2
233+ t = x
234+
235+ aa = (fc - (r + 1 ) * fb + r * fa ) / (h1 * (h1 + h2 ))
236+ bb = (fc - fb ) / h1 - aa * h1
237+ cc = fb
238+
239+ signal_bb = int (math .copysign (1 , bb ))
240+
241+ z = (- bb + signal_bb * math .sqrt (bb ** 2 - 4 * aa * cc )) / (2 * aa )
242+ x = b + z
243+
244+ delta_x = x - t
245+ fx = f (x )
246+
247+ print (f"i = { i :03d} ,\t x = { x :+.4f} ,\t " , end = "" )
248+ print (f"fx = { fx :+.4f} ,\t dx = { delta_x :+.4f} " )
249+
250+ if math .fabs (delta_x ) <= toler and math .fabs (fx ) <= toler :
251+ converged = True
252+ break
253+
254+ if x > b :
255+ a = b
256+ fa = fb
257+ else :
258+ c = b
259+ fc = fb
260+
261+ b = x
262+ fb = fx
263+
264+ root = x
265+ return [root , i , converged ]
266+
267+
205268def newton (f , df , x0 , toler , iter_max ):
206269 """Calculate the root of an equation by the Newton method.
207270
0 commit comments