Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Trabajo Colaborativo No 2
Trabajo Colaborativo No 2
Trabajo Colaborativo No 2
Evaluación unidad 2
Ingeniería en Electrónica
Métodos numéricos/Curso 48
Introducción
Evaluación unidad 2
Punto 1.
2 x1 −6 x 2 +4 x3 −8 x 4= 66
2 x 1 +4 x2 +2 x3 +3 x 4 = −40
7 x1 −7 x 2 −5 x 3 +7 x 4 = 92
−9 x 1−9 x 2+9 x3−7 x 4 = 32
Algoritmo
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# gauss.py
#
# Copyright 2017 Jose Fernando <perseo@Doom>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# fila 4 x 4 Métodos numéricos UNAD
#
import numpy as np
def f(xi):
if(xi == 0): return [ 2, -6, 4, -8, 66]
if(xi == 1): return [ 2, 4, 2, 3, -40]
if(xi == 2): return [ 7, -7, -5, 7, 92 ]
if(xi == 3): return [ -9, -9, 9, -7, 32 ]
def formatearfila():
index = [0, 1, 2, 3]
for i in index:
fila[i] = f(i)
def gauss_eliminar():
orden = 4
while (orden != 0):
i = orden - 1
while(i != 0):
m = -fila[4 -i][4-orden] / fila[4 - orden][4 - orden]
fila[4 - i] = fila[4 - i] + m * fila[4 - orden]
i=i-1
orden = orden - 1
def gauss_reducir():
x[3] = round(fila[3][4] / fila[3][3])
x[2] = round((fila[2][4] - (fila[2][3]*x[3]))/fila[2][2])
x[1] = round((fila[1][4] - fila[1][3]*x[3] - fila[1][2]*x[2]) / fila[1][1])
x[0] =
round((fila[0][4] - fila[0][3]*x[3] - fila[0][2]*x[2] - fila[0][1]*x[1]) /
fila[0][0])
formatearfila()
gauss_eliminar()
gauss_reducir()
print fila
print "\n", x
Paso 1 eliminación.
[[ 2 -6 4 -8 66 ]
[ 2 4 2 3 -40 ]
[ 7 -7 -5 7 92 ]
[ -9 -9 9 -7 32 ]]
[[ 2 -6 4 -8 66 ]
[ 0 10 -2 11 -106 ]
[ 0 14 -19 35 -139 ]
[ 0 -36 27 -43 329 ]
[[ 2 -6 4 -8 66 ]
[ 0 10 -2 11 -106 ]
[ 0 0 -16.2 19.6 9. 4 ]
[ 0 0 0 20.55555556 -41.11111111]]
Métodos numéricos 6
2 x 1−6 x 2+ 4 x3−8 x 4 = 66
10 x2 −2 x3 +11 x 4= −106
−16.2 x 3 +19.6 x 4= 9.4
20.55555556 x 4 = −41.11111111
Paso 2 reducir.
20.55555556 x 4= −41.11111111
41.11111111
x 4= −
20.55555556
x 4= −2
(9.4−19.6∗(−2))
x 3=
−16.2
x 3=−3
10 x 2−2(−3)+11(−2)= −106
(−106+2(−3)−11(−2))
x 2=
10
x 2= −9
x 1= 4
x 1= 4 x 2= −9 x 3= −3 x 4 = −2
Métodos numéricos
7
Punto 2.
Jordan.
5 x 1 +2 x 2+5 x 3 +6 x 4= −90
−1 x 1−6 x 2 +4 x 3+5 x 4 = −104
−3 x 1−5 x 2 −7 x 3 −3 x4 = 63
2 x 1−5 x 2−9 x3−9 x 4 = 108
Algoritmo
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# gauss_jordan.py
#
# Copyright 2017 Jose Fernando <perseo@Doom>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# fila 4 x 4 Métodos numéricos UNAD
#
import numpy as np
def f(xi):
if(xi == 0): return [ 5., 2., 5., 6., -90. ]
if(xi == 1): return [ -1., -6., 4., 5., -104.]
if(xi == 2): return [ -3., -5., -7., -3., 63. ]
if(xi == 3): return [ 2., -5., -9., -9., 108.]
def formatearfila():
index = [0, 1, 2, 3]
for i in index:
fila[i] = f(i)
def triangular():
orden = 4
while (orden != 0):
i = orden - 1
while(i != 0):
m = -fila[4 -i][4-orden] / fila[4 - orden][4 - orden]
fila[4 - i] = fila[4 - i] + m * fila[4 - orden]
i=i-1
orden = orden - 1
def inv_triangular():
orden = 4
while (orden != 0):
i = orden - 1
while(i != 0):
m = -fila[i - 1][orden - 1] / fila[orden - 1][orden - 1]
fila[i - 1] = fila[i - 1] + m * fila[orden - 1]
i=i-1
orden = orden - 1
def gauss_reducir():
x[3] = round(fila[3][4] / fila[3][3])
x[2] = round((fila[2][4] - (fila[2][3]*x[3]))/fila[2][2])
x[1] = round((fila[1][4] - fila[1][3]*x[3] - fila[1][2]*x[2]) / fila[1][1])
x[0] =
round((fila[0][4] - fila[0][3]*x[3] - fila[0][2]*x[2] - fila[0][1]*x[1]) /
fila[0][0])
formatearfila()
triangular()
inv_triangular()
gauss_reducir()
print fila
print x
Métodos numéricos
9
5 x 1 +2 x 2+5 x 3 +6 x 4= −90
−1 x 1−6 x 2 +4 x 3+5 x 4 = −104
−3 x 1−5 x 2 −7 x 3 −3 x4 = 63
2 x 1−5 x 2−9 x3−9 x 4 = 108
Paso 1 eliminación
[[ 5. 2. 5. 6. -90.]
[ -1. -6. 4. 5. -104.]
[ -3. -5. -7. -3. 63.]
[ 2. -5. -9. -9. 108.]]
como pivote
[[ 5. 2. 5. 6. -90. ]
[ 0. -5.6 5. 6.2 -122. ]
[ 0. -3.8 -4. 0.6 9. ]
[ 0. -5.8 -11. -11.4 144. ]]
Métodos numéricos
10
[[ 5. 2. 5. 6. -90. ]
[ 0. -5.6 5. 6.2 -122. ]
[ 0. 0. -7.39285714 -3.60714286 91.78571429]
[ 0. 0. -16.17857143 -17.82142857 270.35714286]]
[[ 5. 2. 5. 6. -90. ]
[ 0. -5.6 5. 6.2 -122. ]
[ 0. 0. -7.39285714 -3.60714286 91.78571429]
[ 0. 0. 0. -9.92753623 69.49275362]]
[[ 5. 2. 5. 0. -48. ]
[ 0. -5.6 5. 0. -78.6 ]
[ 0. 0. -7.39285714 0. 66.53571429]
[ 0. 0. 0. -9.92753623 69.49275362]]
[[ 5. 2. 0. 0. -3. ]
[ 0. -5.6 0. 0. -33.6 ]
[ 0. 0. -7.39285714 0. 66.53571429]
[ 0. 0. 0. -9.92753623 69.49275362]]
Métodos numéricos
11
[[ 5. 0. 0. 0. -15. ]
[ 0. -5.6 0. 0. -33.6 ]
[ 0. 0. -7.39285714 0. 66.53571429]
[ 0. 0. 0. -9.92753623 69.49275362]]
Reducimos
[[ 1 0. 0. 0. -3.]
[ 0. 1 0. 0. 6.]
[ 0. 0. 1 0. -9.]
[ 0. 0. 0. 1 -7.]]
x 1= −3 x 2= 6 x 3= −9 x 4 = −7
Punto 3
3 x− y−z=1
−x +3 y + z=3
2 x + y +4 z=7
Utilizar un ξ < 1%
linux.com/mathematics/linear-systems/article/jacobi-method.
Métodos numéricos
12
[ ][]
3 −1 −1 1
−1 3 1 3
2 1 4 7
donde A
[ ]
3 −1 −1
−1 3 1
2 1 4
y b
[ 1 3 7]
[ ] [ ] [ ]
3 0 0 0 0 0 0 1 1
D = 0 3 0 L = 1 0 0 U = 0 0 −1
0 0 4 −2 −1 0 0 0 0
[ ]
−1
1 /3 0 0
D = 0 1/ 3 0
0 0 1/ 4
Métodos numéricos
[ ][[ ] [ ]] [
] []
1/3 0 0 0 0 0 0 1 1
1/3 0 0 1
0 1 /3 0 1 0 0 0 0 −1
0 1 /3 0 3
X(k+1) = 0 0 1/ 4 −2 −1 0 + 0 0 0
X(k) + 0 0 1/ 4 7
[ ][[
]] [ ]
1/3 0 0 0 1 1
1/ 3
0 1 /3 0 1 0 −1
1
X(k+1) = 0 0 1/ 4 −2 −1 0
X(k) + 7/4
[ ] [
]
0 1 /3 1/3
1/ 3
(k+1)
X = 1/3 0 −1/3 X(k)
+ 1
−1/2 −1 / 4 0
7/ 4
[ ] [ ]
[ ] [ ]
( k+1)
( k)
X 0 1 /3 1/ 3
X 1/ 3
Y ( k+1) = 1/3 0 −1/3
Y ( k) + 1
Z(k +1) −1/2 −1 / 4 0
Z(k ) 7/ 4
Métodos numéricos
14
[ ][ ][ ]
( k+1)
X 1/ 3 yk 1/ 3 z k 1/ 3
k k
Y ( k+1) =
1/ 3 x −1/3 z + 1
Z(k +1) k
−1 /2 x −1/ 4 y
k 7/4
[ ][ ]
( k+1)
X 1 /3 + 1 /3 y k +1 /3 z k
k k
Y ( k+1) =
1 + 1/3 x −1 /3 z
k k
Z(k +1) 7 / 4 −1 /2 x −1 /4 y
Al ser un método iterativo, que se repite “n” veces podemos hacer un corto
algoritmo que
Iteración No Xn Yn Zn
0 0 0
0
1 0.333333333333 1.0
1.75
2 1.25 0.527777777778
1.33333333333
3 0.953703703704 0.972222222222
0.993055555556
4 0.988425925926 0.986882716049
1.03009259259
5 1.00565843621 0.986111111111
1.00906635802
6 0.998392489712 0.998864026063
1.00064300412
7 0.999835676726 0.999249828532
1.00108774863
8 1.00011252572 0.999582642699
1.0002697045
9 0.999950782401 0.999947607072
1.00004807647
10 0.999998561179 0.999967568645
1.00003770703
11 1.00000175856 0.999986951383
1.00000882725
12 0.999998592877 0.99999764377
1.00000238287
13 1.00000000888 0.999998736667
1.00000129262
14 1.00000000976 0.999999572088
1.00000031139
15 0.99999996116 0.999999899457
1.0000001021
X = 0.99999996116 Y = 0.999999899457 Z =
1.0000001021
Métodos numéricos
16
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x =[0, 0.333333333333,
1.25 ,0.953703703704, 0.988425925926 ,
1.00565843621, 0.998392489712,
0.999835676726, 1.00011252572 ,
0.999950782401, 0.999998561179,
1.00000175856, 0.999998592877,
1.00000000888, 1.00000000976,
0.99999996116]
y =[0, 1.
0, 0.527777777778,
0.972222222222, 0.986882716049,
0.986111111111, 0.998864026063,
0.999249828532, 0.999582642699,
0.999947607072, 0.999967568645,
0.999986951383, 0.99999764377,
0.999998736667, 0.999999572088,
0.999999899457]
z =[0, 1.75,
1.33333333333, 0.993055555556,
1.03009259259, 1.00906635802,
1.00064300412, 1.00108774863,
1.0002697045, 1.00004807647,
1.00003770703, 1.00000882725,
1.00000238287, 1.00000129262,
1.00000031139, 1.0000001021]
ax.set_xlabel('Eje X')
ax.set_ylabel('Eje Y')
ax.set_zlabel('Eje Z')
plt.show()
Gracias a la gráfica podemos observar como los diferentes valores convergen hacia
el punto
1,1,1
Métodos numéricos
17
Punto 4
Reordenamos el sistema
De esta manera logramos que en la diagonal esten los coeficientes de mayor valor y
así
Luego:
x1 = 2.6167
Métodos numéricos 18
Reemplazamos en x2
x2 = -2.7945
Reemplazamos en x3
x3 = 7.0056
Primera iteración
x1 = 2.9906
Reemplazamos en x2
x2 = -2.4996
Reeplazamos en x3
x3 = 7.0003
Segunda iteración
x1 = 3.0000
Reemplazamos en x2
x2 = -2.5000
Reeplazamos en x3
x3 = 7.0000
Métodos numéricos
19
Comparamos los valores obtenidos de las dos úlrimas iteraciones para cumplir con la
condición
de error.
X 1 |3.000−2.9906|=9.4e-3
E
X 2 |−2.5000−(−2.4996)|=4.0000e-04
E
X 3 |7.0000−7.0003|=3.0000e-04
E
x1 = 3.0000
x2 = -2.5000
x3 = 7.0000
Podemos observar en la gráfica como los valores convergen a los puntos encontrados