Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
restrepo
GitHub Repository: restrepo/ComputationalMethods
Path: blob/master/homework/Homework_2018_1_02_1032478036.ipynb
934 views
Kernel: Python 3

Fixed-point iteration

TAREA: Encontrar las tres raices de la función f(x)=x2cos(2x)f(x) = x^2\cos(2x) utilizando optimize.fixed_point

from scipy import optimize %pylab inline import matplotlib.pyplot as plt import numpy as np
Populating the interactive namespace from numpy and matplotlib
/usr/local/lib/python3.4/dist-packages/IPython/core/magics/pylab.py:160: UserWarning: pylab import has clobbered these variables: ['f'] `%matplotlib` prevents importing * from pylab and numpy "\n`%matplotlib` prevents importing * from pylab and numpy"
#Gráfica de la funcion x = np.linspace(-1,1,100) plt.plot(x,x**2*np.cos(2*x)) plt.grid()
Image in a Jupyter notebook
def f(x): return x**2*np.cos(2*x) def g(x): return x-f(x) root1=optimize.fixed_point(g,1) root2=optimize.fixed_point(g,20) root3=optimize.fixed_point(g,0.1) print ('Algunas raíces de la función son: x={} , x={} y x={}'.format(root1,root2,root3))
Algunas raíces de la función son: x=0.7853981633974483 , x=-0.7853981633974483 y x=1.2787076310012914e-09