Está en la página 1de 1

In [1]: # Evaluate value of 2x3 - 6x2 + 2x - 1 for x = 3

poly[] = {2, -6, 2, -1}, x = 3

# Evaluate value of 2x3 + 3x + 1 for x = 2


poly[] = {2, 0, 3, 1}, x = 2
2

# Evaluate value of 2x + 5 for x = 5


poly[] = {2, 5}, x = 5

File "<ipython-input-1-235773f51a2b>", line 2


Input: poly[] = {2, -6, 2, -1}, x = 3
^
SyntaxError: invalid syntax

In [ ]:

In [3]: # Evaluar el valor de la función 2x3 + 3x + 1 para x = 2


poly[] = {2, 0, 3, 1}, x = 2

File "<ipython-input-3-509b45e1cef7>", line 2


poly[] = {2, 0, 3, 1}, x = 2
^
SyntaxError: invalid syntax

In [81]: from math import *


# Numpy es una librería para realizar cálculo numérico en python

import numpy as np
import matplotlib.pyplot as plt
x=np.arange(-10,10,0.1)
#print(x)
# f(x)
#print(pi)
plt.plot(x,np.cos(x),'red')
plt.xlabel('$Eje X $')
plt.ylabel('Eje Y ')
plt.title('Función coseno')
plt.show()

In [154… from math import *


import math
plt.style.use('seaborn')
%matplotlib notebook
#matplotlib inline
x=np.linspace(-2,5.6,100)
#x
def f(x):
return (x-3)**2-3
def g(x):
return np.cos(x)

In [155… fig, ax=plt.subplots()


ax.plot(x,f(x))
ax.plot(x,g(x))
xmin, xmax =ax.get_xlim()
ymin, ymax =ax.get_ylim()
ax.grid(True, linestyle='-')
ax.annotate("", xy=(xmax,0),xytext=(xmin,0),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
ax.annotate("", xy=(0,ymax),xytext=(0,ymin),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
plt.show()

In [181… plt.style.use('seaborn')
%matplotlib notebook
#matplotlib inline
x=np.linspace(-2,2,100)
#x
def f(x):
return x**2-2
def g(x):
return -1/x

In [182… fig, ax=plt.subplots()


ax.plot(x,f(x))
ax.plot(x,g(x))
xmin, xmax =ax.get_xlim()
ymin, ymax =ax.get_ylim()
ax.grid(True, linestyle='-')
ax.annotate("", xy=(xmax,0),xytext=(xmin,0),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
ax.annotate("", xy=(0,ymax),xytext=(0,ymin),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
plt.show()

In [183… plt.style.use('seaborn')
%matplotlib notebook
#matplotlib inline
x=np.linspace(0.5,2,100)
#x
def f(x):
return x**2-2+1/x

In [184… fig, ax=plt.subplots()


ax.plot(x,f(x))
#ax.plot(x,g(x))
xmin, xmax =ax.get_xlim()
ymin, ymax =ax.get_ylim()
ax.grid(True, linestyle='-')
ax.annotate("", xy=(xmax,0),xytext=(xmin,0),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
ax.annotate("", xy=(0,ymax),xytext=(0,ymin),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
plt.show()

In [ ]:

In [149… from math import *


import math
plt.style.use('seaborn')
%matplotlib notebook
#matplotlib inline
x=np.linspace(-2,5.6,100)
#x
def f(x):
return np.log(x**2+1)-math.e**(x/2)*np.cos(pi*x)
#math.e**x
#np.cos(pi*x)
#math.log(x**2+1)+math.exp**(x/2)*np.cos(pi*x)
#(x-3)**2-3

In [150… fig, ax=plt.subplots()


ax.plot(x,f(x))
xmin, xmax =ax.get_xlim()
ymin, ymax =ax.get_ylim()
ax.grid(True, linestyle='-')
ax.annotate("", xy=(xmax,0),xytext=(xmin,0),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
ax.annotate("", xy=(0,ymax),xytext=(0,ymin),
arrowprops=dict(color='red',width=1.5,headwidth=8,headlength=10))
plt.show()

In [ ]:

In [89]: from math import *

def f(x):
return log(x**2+1)-exp(x/2)*cos(pi*x)
#exp(-x)-x
#x*sin(x)-1
# ((x-3)**2)-3
#cos(x)-pow(x,3)

In [90]: def biseccion(a,b,tol):


m1=a
m=b
k=0
if (f(a)*f(b)>0):
print(" La función no cambia de signo ")
while (abs(m1-m)>tol):
m1=m
m=(a+b)/2
if (f(a)*f(m)<0): # cambia de signo en [a,m]
b=m
if (f(m)*f(b)<0): # cambia de signo en [m,b]
a=m
print(" El intervalo es [",a,",",b,"]")
k=k+1
print("x",k, "=",m, "es una buena aproximacion ")

In [92]: #biseccion(0,pi,10**(-6))
#biseccion(4,5,10**(-3))
#biseccion(0,2,10**(-3))
#biseccion(0,1,10**(-3))
biseccion(5,6,10**(-3))

El intervalo es [ 5.5 , 6 ]
El intervalo es [ 5.5 , 5.75 ]
El intervalo es [ 5.5 , 5.625 ]
El intervalo es [ 5.5625 , 5.625 ]
El intervalo es [ 5.5625 , 5.59375 ]
El intervalo es [ 5.5625 , 5.578125 ]
El intervalo es [ 5.5625 , 5.5703125 ]
El intervalo es [ 5.56640625 , 5.5703125 ]
El intervalo es [ 5.568359375 , 5.5703125 ]
El intervalo es [ 5.568359375 , 5.5693359375 ]
x 10 = 5.5693359375 es una buena aproximacion

In [ ]:

También podría gustarte