0% found this document useful (0 votes)
32 views4 pages

Ejericicio #2

This document contains code for analyzing a numerical function using bisection and modified false position root-finding algorithms in Python. It defines the functions, plots the function, and calculates the root using both methods, printing the results.

Uploaded by

Rómulo Orellana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Ejericicio #2

This document contains code for analyzing a numerical function using bisection and modified false position root-finding algorithms in Python. It defines the functions, plots the function, and calculates the root using both methods, printing the results.

Uploaded by

Rómulo Orellana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

UNIVERSIDAD DE EL SALVADOR

FACULTAD DE INGENIERIA Y ARQUITECTURA


ESCUELA DE INGENIERIA ELECTRICA

ANALISIS NUMERICO (ANN115)


CATEDRÁTICO: ING. CARLOS OSMIN POCASANGRE JIMENEZ

EJERCICIO #2
-ORELLANA ARANIVA RÓMULO RONALDO OA21011

CIUDAD UNIVERSITARIA, 08 DE MARZO DE 2023


E JE R C IC I O # 2

import numpy as np
import pylab as plt
from math import exp

# def get_funtion(x):
# '''Defunicio de la Fucnion'''
# return -0.5 * x * x + 2.5 * x + 4.5

def get_funtion(x):
'''Defunicio de la Fucnion'''
return 9.8 * 68.1 / x * (1.0 - exp(-1.0 * x / 68.1 * 10.0)) - 40.0

def bisect(xl, xu, xr, es, imax):


'''Funcion Bisección para el calculo de raiz de ecuaciones'''
iter = 0
ea = 1
while ea > es and iter < imax:
print(xl, xu, xr, ea, iter)
xrold = xr
xr = (xl + xu) / 2.0
iter += 1
if xr != 0:
ea = abs( (xrold - xr)/ xr) * 100.0
test = get_funtion(xl) * get_funtion(xr)
if test < 0:
xu = xr
elif test > 0:
xl = xr
else:
ea = 0.0
return xr

def ModFalsePos(xl, xu, xr, es, imax):


iter = 0
fl = get_funtion(xl)
fu = get_funtion(xu)
ea = 1
while ea > es and iter < imax:
print(xl, xu, xr, ea, iter)
xrold = xr
il = 0
iu = 0
xr = xu - fu * (xl - xu) / (fl - fu)
fr = get_funtion(xr)
iter += 1
if xr != 0 :
ea = abs( (xrold - xr)/ xr) * 100.0
test = fl * fr
if test < 0:
xu = xr
fu = get_funtion(xu)
iu = 0
il += 1
if il >= 2 :
fl /= 2
elif test > 0 :
xl = xr
fl = get_funtion(xl)
il = 0
iu += 1
if iu >= 2 :
fu /= 2
else:
ea = 0.0
return xr

x = np.arange(stat=1.0, step=0.1,stop=20
f_x = np.array([])
for val in x:
f_x = np.append(f_x, get_funtion(val))

plt.plot(x, f_x)
plt.grid()
plt.show()

# print(ModFalsePos(-2,0,-1.4,0.0001,50))
# print(ModFalsePos(5,8,6,0.0001,50))

xr = bisect(12.5,15,15.0001,0.0001,50)
xr = ModFalsePos(8.0, 15.1, 10.0, 0.0001, 50)
print(xr)
print(get_funtion(xr))

You might also like