I need to write a proper implementation of the Ridder’s method in Matlab. I must define the function as
function [x sol, f at x sol, N iterations] = Ridders(f, x1, x2, eps f, eps x)
The explanation I was given is:
-
bracket the roots (x1, x2)
-
evaluate the midpoint (x1 + x2)/2
-
find new approximation for the root
x4 = x3 + sign(f1 - f2) [f3/((f3)^2 - f1f2)^1/2)](x3 - x1) -
check if x4 satisfies the convergence condition. if yes, stop. if not…
-
rebracket the root using x4 and whichever of x1, x2, or x3 is closer to the root
-
loop back to 1
I have no idea how to implement this in matlab. Help?
In Matlab, you would define your function as:
In your case if you would like x4 (i.e root) to be your output, you would do: