Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #EJERCICIO 4
- #APARTADO 1: CAMBIAR EL CORCHETE COPYPASTEAR MATRIZ, REESCRIBIR LOS MENOS
- print '\n Apartado 1:'
- print'\nMatriz A:'
- A4 = matrix(QQ, 5, [1,3,-5,1,-3,2,5,-8,1,-3,-1,-3,5,-4,-6,2,8,-2,4,-10,0,-3,2,-2,9,]).transpose(); show(A4)
- print '\nVector b:'
- b4 = vector(QQ, [8,21,-18,4,-20,]); show(b4)
- print '\n======================Descomposicion LU=======================\n'
- L4, U4 = descompLU(A4)
- print '\nMatriz L:'
- show(L4)
- print '\nMatriz U:'
- show(U4)
- print '\n======================Descomposicion PLU======================='
- P42, L42, U42 = descompPLU(A4)
- print '\nMatriz P:'
- show(P42)
- print '\nMatriz L:'
- show(L42)
- print '\nMatriz U:'
- show(U42)
- #SI EL APARTADO 2 SE HA HECHO POR LU, QUITAR COMILLAS DE AQUI ABAJO
- """print 'RESOLVIENDO POR LU SI EL AP2 SE HA HECHO POR LU:'
- g = modifica_lado_derecho(L4, b4)
- print '\nG (SOLUCION AL APARTADO 3):'
- show(g) # obtenemos la solución del sistema auxiliar
- z4 = sustitucion_regresiva2(U4, g) # obtenemos la solución final por sustitución regresiva.
- show(z4)
- show(A4*z4) # comprobamos la solución
- print('==============================END=========================')"""
- #SI EL APARTADO 2 SE HA HECHO POR PLU, QUITAR COMILLAS DE AQUI ABAJO
- bp = P42*b4
- print '\nP*b = bp:'
- show(bp4)
- g = modifica_lado_derecho(L42, bp)
- print '\nG (SOLUCION AL APARTADO 3):'
- show(g) # resolvemos el sistema auxiliar
- z = sustitucion_regresiva2(U42, g) # obtenemos la solución final para el primer vector b propuesto
- print '\nZ:'
- show(z)
- print '\nA*Z:'
- show(A4*z) # comprobamos que todo ha ido bien y la solución es correcta
- print('==============================END=========================')
- print '\nAx=b'
- show(A4.solve_right(b4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement