Documentos de Académico
Documentos de Profesional
Documentos de Cultura
LEGUÍA” DE BAGUA
V CICLO
METODOS NUMERICOS
PYTHON
ALUMNOS
CENTURION MESONES CYNTHIA DARSY
DOCENTE
ROGER ALVARO FERNÁNDEZ VILLARROEL
BISECCION
@author: CYNTHIA
"""
import numpy as np
a=0
b = 0.5
tolera = 0.001
tramo = abs(b-a)
while not(tramo<=tolera):
fa = fx(a)
fb = fx(b)
c = b - fb*(a-b)/(fa-fb)
fc = fx(c)
cambia = np.sign(fa)*np.sign(fc)
if (cambia > 0):
tramo = abs(c-a)
a=c
else:
tramo = abs(b-c)
b=c
raiz = c
print(raiz)
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
import numpy as np
fx = lambda x: x**3+14*x**2-7*x-2
a = 0.5
b=1
tolera = 0.001
tramo = abs(b-a)
while not(tramo<=tolera):
fa = fx(a)
fb = fx(b)
c = b - fb*(a-b)/(fa-fb)
fc = fx(c)
cambia = np.sign(fa)*np.sign(fc)
if (cambia > 0):
tramo = abs(c-a)
a=c
else:
tramo = abs(b-c)
b=c
raiz = c
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
import numpy as np
fx = lambda x: 2*x**3-14*x**2+24*x
a = 3.5
b = 4.5
tolera = 0.001
tramo = abs(b-a)
while not(tramo<=tolera):
fa = fx(a)
fb = fx(b)
c = b - fb*(a-b)/(fa-fb)
fc = fx(c)
cambia = np.sign(fa)*np.sign(fc)
if (cambia > 0):
tramo = abs(c-a)
a=c
else:
tramo = abs(b-c)
b=c
raiz = c
print(raiz)
NEWTON RAPSON
@author: CYNTHIA
"""
@author: CYNTHIA
"""
def f(x):
return 4*x**3-10*x**2+2*x+5
x0=2.5;
x1=1.5;
x2=0
fx0=f(x0)
fx1=f(x1)
tol=0.0005
while (abs(fx1)>tol):
x2=x1-((fx1*(x0-x1))/(fx0-fx1))
print (x2)
fx2=f(x2)
x0=x1
x1=x2
fx0=f(x0)
fx1=f(x1)
print('La aproximacion es', x2)
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
def f(x):
return 8*x**6 - 10*x**4 + 3*x**2 - 6
x0=2;
x1=1;
x2=0
fx0=f(x0)
fx1=f(x1)
tol=0.0005
while (abs(fx1)>tol):
x2=x1-((fx1*(x0-x1))/(fx0-fx1))
print (x2)
fx2=f(x2)
x0=x1
x1=x2
fx0=f(x0)
fx1=f(x1)
print('La aproximacion es', x2)print('La
aproximacion es', x2)
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
def f(x):
return 9*x**2 + 6*x -7
x0=1;
x1=0.5;
x2=0
fx0=f(x0)
fx1=f(x1)
tol=0.0005
while (abs(fx1)>tol):
x2=x1-((fx1*(x0-x1))/(fx0-fx1))
print (x2)
fx2=f(x2)
x0=x1
x1=x2
fx0=f(x0)
fx1=f(x1)
print('La aproximacion es', x2)
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
def f(x):
return 5*x**4 - 2*x**2 - 10
x0=2;
x1=1;
x2=0
fx0=f(x0)
fx1=f(x1)
tol=0.0005
while (abs(fx1)>tol):
x2=x1-((fx1*(x0-x1))/(fx0-fx1))
print (x2)
fx2=f(x2)
x0=x1
x1=x2
fx0=f(x0)
fx1=f(x1)
print('La aproximacion es', x2)
# -*- coding: utf-8 -*-
"""
@author: CYNTHIA
"""
def f(x):
return 2*x**3 - 10*x - 3
x0=3;
x1=2;
x2=0
fx0=f(x0)
fx1=f(x1)
tol=0.0005
while (abs(fx1)>tol):
x2=x1-((fx1*(x0-x1))/(fx0-fx1))
print (x2)
fx2=f(x2)
x0=x1
x1=x2
fx0=f(x0)
fx1=f(x1)
print('La aproximacion es', x2)