You are on page 1of 7

13/10/22, 20:32 Untitled8.

ipynb - Colaboratory

Sebastián Alejandro Peralta Solís

from math import*


import numpy as np
from matplotlib import pyplot

Pregunta 1 parte 1

def f1(x):
return 3*x**2+2*cos(6*x)-3*x
x=np.linspace(-1,1,100)
pyplot.plot(x,[f1(i) for i in x],"lightblue")
pyplot.axhline(0, color="blue")
pyplot.axvline(0, color="red")

<matplotlib.lines.Line2D at 0x7f748ba28c50>

Pregunta 1 parte 2

def func(x):
return x-(3*x**2+2*cos(6*x)-3*x)/(6*x-12*sin(6*x)-3)
def newton (x0,tol):
k=1
x1=func(x0)
print("k | x0")
while abs(x1-x0)>tol:
print(k," | ","{:.6f}".format(x0))
x0=x1
x1=func(x0)
k=k+1
return print("La raiz es:","{:.6f}".format(x1))
newton(0.3,0.0001)

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 1/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory

k | x0
1 | 0.300000
2 | 0.215847
La raiz es: 0.218612

Pregunta 2 parte 1

def f1(x):
return 3*x**2+2*np.log(6*x)-12*x+4
x=np.linspace(-3,3,100)
pyplot.plot(x,[f1(i) for i in x],"lightblue")
pyplot.axhline(0, color="blue")
pyplot.axvline(0, color="red")

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:2: RuntimeWarning: inval

<matplotlib.lines.Line2D at 0x7f74894b2a50>

Pregunta 2 parte 2

def g(x):
return x-(3*x**2+2*np.log(6*x)-12*x+4)/(6*x+2/x-12)

def secante1(x0,tol):
k=1
x1=g(x0)
print("k | x0")
while abs(x1-x0)>tol:
print(k," | ","{:.8f}".format(x0))
x0=x1
x1=g(x0)
k=k+1
return print("La raiz es:","{:.6f}".format(x1))
secante1(0.6,0.0001)
secante1 (3.4,0.0001)

k | x0
1 | 0.60000000

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 2/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory

2 | 0.68721073
La raiz es: 0.687923
k | x0
1 | 3.40000000
2 | 2.96486789
3 | 2.87976373
La raiz es: 2.876261

Pregunta 3 parte 1

def f1(x):
return 4*x**2+(x**2/3)*np.log(x+4)
x=np.linspace(-5,3,1000)
pyplot.plot(x,[f1(i) for i in x],"lightblue")
pyplot.axhline(0, color="blue")
pyplot.axvline(0, color="red")

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:2: RuntimeWarning: in

<matplotlib.lines.Line2D at 0x7f7489440210>

def f1(x):
return (x**2+8*sin(x/3-5))
x=np.linspace(-7,7,1000)
pyplot.plot(x,[f1(i) for i in x],"lightblue")
pyplot.axhline(0, color="blue")
pyplot.axvline(0, color="red")

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 3/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory

<matplotlib.lines.Line2D at 0x7f748945b3d0>

def f1(x):
return (4*x**2+(x**2/3)*np.log(x+4))-(x**2+8*sin(x/3-5))
x=np.linspace(-5,3,1000)
pyplot.plot(x,[f1(i) for i in x],"lightblue")
pyplot.axhline(0, color="blue")
pyplot.axvline(0, color="red")

/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:2: RuntimeWarning: in

<matplotlib.lines.Line2D at 0x7f7489412b10>

Pregunta 3 parte 2

def g(x):
return x-((4*x**2+((x**2)/3)*np.log(x+4))-(x**2+8*sin((x/3)-5)))/(((2*x**2)*np.log(x+4)+
def newton(x0,tol):
k=1
x1=g(x0)
print('k | x0')
while abs(x1-x0)>tol:
print(k,'|','{:.4f}'.format(x0))
x0=x1
x1=g(x0)
k=k+1
return print('{:.4f}'.format(x1))

newton(-1.5,0.0001)

k | x0
1 | -1.5000
2 | -1.4769
3 | -1.4574
4 | -1.4407
5 | -1.4264
6 | -1.4142
7 | -1.4037

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 4/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory

8 | -1.3946
9 | -1.3869
10 | -1.3801
11 | -1.3743
12 | -1.3693
13 | -1.3650
14 | -1.3612
15 | -1.3580
16 | -1.3552
17 | -1.3527
18 | -1.3506
19 | -1.3488
20 | -1.3472
21 | -1.3458
22 | -1.3446
23 | -1.3436
24 | -1.3427
25 | -1.3419
26 | -1.3412
27 | -1.3407
28 | -1.3401
29 | -1.3397
30 | -1.3393
31 | -1.3390
32 | -1.3387
33 | -1.3384
34 | -1.3382
35 | -1.3380
36 | -1.3379
37 | -1.3377
38 | -1.3376
-1.3374

def g(x):
return x-((4*x**2+((x**2)/3)*np.log(x+4))-(x**2+8*sin((x/3)-5)))/(((2*x**2)*np.log(x+4)+
def newton(x0,tol):
k=1
x1=g(x0)
print('k | x0')
while abs(x1-x0)>tol:
print(k,'|','{:.4f}'.format(x0))
x0=x1
x1=g(x0)
k=k+1
return print('{:.4f}'.format(x1))
newton(1.5,0.0001)

3 | 1.4990
4 | 1.4985
5 | 1.4981
6 | 1.4976
7 | 1.4972
8 | 1.4968
9 | 1.4964
10 | 1.4960
11 | 1.4956
12 | 1.4952
13 | 1.4948
14 | 1 4944
https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 5/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory
14 | 1.4944
15 | 1.4941
16 | 1.4938
17 | 1.4934
18 | 1.4931
19 | 1.4928
20 | 1.4925
21 | 1.4922
22 | 1.4919
23 | 1.4916
24 | 1.4913
25 | 1.4911
26 | 1.4908
27 | 1.4906
28 | 1.4903
29 | 1.4901
30 | 1.4898
31 | 1.4896
32 | 1.4894
33 | 1.4892
34 | 1.4890
35 | 1.4888
36 | 1.4886
37 | 1.4884
38 | 1.4882
39 | 1.4880
40 | 1.4878
41 | 1.4877
42 | 1.4875
43 | 1.4873
44 | 1.4872
45 | 1.4870
46 | 1.4869
47 | 1.4867
48 | 1.4866
49 | 1.4865
50 | 1.4863
51 | 1.4862
52 | 1.4861
53 | 1.4860
54 | 1.4858
55 | 1.4857
56 | 1.4856
57 | 1.4855
58 | 1.4854
59 | 1.4853
1.4851

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 6/7
13/10/22, 20:32 Untitled8.ipynb - Colaboratory

Productos de pago de Colab - Cancelar contratos

check 0 s completado a las 20:31

https://colab.research.google.com/drive/1QmqdbEVpccXlPERmnT-lz27nxEs3in91#scrollTo=GRHik3ltHfC1&printMode=true 7/7

You might also like