Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from math import sqrt
- from scipy.misc import derivative
- def newton_method(x, x1, function):
- return x-(function(x)/derivative(function, x))
- def drying_method(x0, x1, function):
- return (x0*function(x1)-x1*function(x0))/(function(x1)-function(x0))
- def bissection(x0,x1,function,precision=1e-3):
- if x0 > x1:
- x0,x1 = x1,x0
- k = 0
- mei = (x0+x1)/2.0
- while abs(x1-x0)>=precision and abs(function(mei))>=precision:
- k += 1
- if function(mei)*function(x0)<=0:
- x1 = mei
- else:
- x0 = mei
- mei = (x0+x1)/2.0
- # print str(mei)
- return mei,k
- def fixed_point_template(x0,x1,iteration_function,function,precision=1e-3):
- k = 0
- x = iteration_function(x0,x1,function)
- while abs(x-x1)>=precision and abs(function(x1))>=precision:
- k += 1
- x0,x1 = x1, x
- x = iteration_function(x0,x1,function)
- return x,k
- def chaos_function(x):
- return (8 - sqrt(400-x**2)) * sqrt(900-x**2) + 8 * sqrt(400-x**2)
- # return ((8/sqrt(400-x**2)) - 1) * sqrt(900-x**2) + 8
- def carlos_function(x):
- return (sqrt(400-x**2)*sqrt(900-x**2))/(sqrt(400-x**2)+sqrt(900-x**2))-8
- # x,n = bissection(1.0,20.0,chaos_function)
- x0,x1 = 8,20
- # try:
- #
- # except Exception:
- # print "Errou"
- x,n = fixed_point_template(x0,x1,drying_method,chaos_function)
- print "Chaos:raiz:"+str(x)+", iterations:"+str(n)
- # x,n = fixed_point_template(x0,x1,newton_method,carlos_function)
- # print "Carlo:raiz:"+str(x)+", iterations:"+str(n)
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement