Tutorial Python 2
Tutorial Python 2
Tutorial Python 2
Raíces de ecuaciones:
Métodos Abiertos
a) Bracketing method
b) Diverging open method
c) Converging open method - note speed!
1. Simple Fixed-Point Iteration
• Rearrange the function f(x)=0 so that x is on the left-
hand side of the equation: x=g(x)
• Use the new function g to predict a new value of x -
that is, xi+1=g(xi)
• The approximate error is given by:
x i1 x i
a 100%
x i1
Example
• Solve f(x)=e-x-x
• Re-write as x=g(x) by isolating x
(example: x=e-x)
• Start with an initial guess (here, 0)
I xi |a| % |t| % |t|i/|t|i-1
0 0.0000 100.000
1 1.0000 100.000 76.322 0.763
2 0.3679 171.828 35.135 0.460
3 0.6922 46.854 22.050 0.628
4 0.5005 38.309 11.755 0.533
a) Convergent, 0≤g’<1
b) Convergent, -
1<g’≤0
c) Divergent, g’>1
d) Divergent, g’<-1
2. Newton-Raphson Method
(Also known as Newton’s Method)
Assumptions:
• f(x) is continuous and the first derivative is known
• An initial guess x0 such that f’(x0)≠0 is given
Newton Raphson Method
- Graphical Depiction -
If the initial
guess at the root
is xi, then a
tangent to the
function of xi that
is f’(xi) is
extrapolated
down to the x-
axis to provide
an estimate of the
root at xi+1.
Derivation of Newton’s Method
0 4 33 33 3 1
1 3 9 16 2.4375 0.5625
f (x i1 ) f (x i )
f (x i )
'
x i1 x i
Secant Methods
• Substitution of this approximation for the derivative
to the Newton-Raphson method equation gives:
f (x i )x i1 x i
x i1 x i
f (x i1) f (x i )
x0 , x1 , i 1
( xi xi 1 )
xi 1 xi f ( xi ) ;
f ( xi ) f ( xi 1 )
i i 1
NO Yes
xi 1 xi Stop
Modified Secant Method
In this modified Secant method, only one initial guess is needed :
f ( xi xi ) f ( xi )
f ' ( xi )
xi
f ( xi ) xi f ( xi )
xi 1 xi xi
f ( xi xi ) f ( xi ) f ( xi xi ) f ( xi )
xi
Problem : How to select ?
If not selected properly, the method may diverge .
MATLAB’s fzero Function
• MATLAB’s fzero provides the best qualities of both
bracketing methods and open methods.
• Using an initial guess:
x = fzero(function, x0)
[x, fx] = fzero(function, x0)
• function is a function handle to the function being evaluated
• x0 is the initial guess
• x is the location of the root
• fx is the function evaluated at that root
f(x)=x5-3.5x4+2.75x3+2.125x2-3.875x+1.25
x = roots([1 -3.5 2.75 2.125 -3.875 1.25])
Polynomials (cont)
• MATLAB’s poly function can be used to determine
polynomial coefficients if roots are given:
b = poly([0.5 -1])
• Finds f(x) where f(x) =0 for x=0.5 and x=-1
• MATLAB reports b = [1.000 0.5000 -0.5000]
• This corresponds to f(x)=x2+0.5x-0.5