Advertisement
DekkerBass

ALNP2EJ4

Mar 19th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. #EJERCICIO 4
  2. #APARTADO 1: CAMBIAR EL CORCHETE COPYPASTEAR MATRIZ, REESCRIBIR LOS MENOS
  3. print '\n Apartado 1:'
  4. print'\nMatriz A:'
  5. 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)
  6. print '\nVector b:'
  7. b4 = vector(QQ, [8,21,-18,4,-20,]); show(b4)
  8.  
  9. print '\n======================Descomposicion LU=======================\n'
  10. L4, U4 = descompLU(A4)
  11. print '\nMatriz L:'
  12. show(L4)
  13. print '\nMatriz U:'
  14. show(U4)
  15.  
  16. print '\n======================Descomposicion PLU======================='
  17. P42, L42, U42 = descompPLU(A4)
  18. print '\nMatriz P:'
  19. show(P42)
  20. print '\nMatriz L:'
  21. show(L42)
  22. print '\nMatriz U:'
  23. show(U42)
  24.  
  25.  
  26. #SI EL APARTADO 2 SE HA HECHO POR LU, QUITAR COMILLAS DE AQUI ABAJO
  27. """print 'RESOLVIENDO POR LU SI EL AP2 SE HA HECHO POR LU:'
  28. g = modifica_lado_derecho(L4, b4)
  29. print '\nG (SOLUCION AL APARTADO 3):'
  30. show(g)  # obtenemos la solución del sistema auxiliar
  31. z4 = sustitucion_regresiva2(U4, g)    # obtenemos la solución final por sustitución regresiva.
  32. show(z4)
  33. show(A4*z4)  # comprobamos la solución
  34. print('==============================END=========================')"""
  35.  
  36. #SI EL APARTADO 2 SE HA HECHO POR PLU, QUITAR COMILLAS DE AQUI ABAJO
  37. bp = P42*b4
  38. print '\nP*b = bp:'
  39. show(bp4)
  40. g = modifica_lado_derecho(L42, bp)
  41. print '\nG (SOLUCION AL APARTADO 3):'
  42. show(g)             # resolvemos el sistema auxiliar
  43. z = sustitucion_regresiva2(U42, g)   #  obtenemos la solución final para el primer vector b propuesto
  44. print '\nZ:'
  45. show(z)
  46. print '\nA*Z:'
  47. show(A4*z)           #  comprobamos que todo ha ido bien y la solución es correcta
  48. print('==============================END=========================')
  49.  
  50. print '\nAx=b'
  51. show(A4.solve_right(b4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement