Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.python > #7604

Decomposizione LU

From Paolo Ferraresi <fp.box@alice.it>
Newsgroups it.comp.lang.python
Subject Decomposizione LU
Date 2016-01-31 11:11 +0100
Organization Aioe.org NNTP Server
Message-ID <n8kmk6$1lnn$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Ciao mi potreste spiegare perché se metto caso = 1 ho una soluzione 
corretta del sistema lineare e se metto caso = 2 (cioè un altro sistema) 
la soluzione è sbagliata? Sto diventando forse matto!?

#import linalg package of the SciPy module for the LU decomp
import scipy.linalg as linalg
#import NumPy
import numpy as np

caso = 2 # inserire 1 o 2
if caso == 1:
     A = np.array([[2., 1., 1.],[1., 3., 2.],[1., 0., 0.]])
     B = np.array([4., 5., 6.])
elif caso == 2:
     A = np.array([[1,3,4,5],[2,1,1,0],[2,3,1,-1],[0,4,3,2]])
     B = np.array([2,3,-1,4])

#call the lu_factor function
LU = linalg.lu_factor(A)

#solve given LU and B
x = linalg.lu_solve(LU, B)
print ("Solutions:\n",x)

P, L, U = linalg.lu(A)
y1 = linalg.solve(L,B)
x1 = linalg.solve(U,y1)
print ("Solutions with LU:\n",x1)

v = A.dot(x)
print ("Verifica:\n",v)
v = A.dot(x1)
print ("Verifica:\n",v)

Back to it.comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Decomposizione LU Paolo Ferraresi <fp.box@alice.it> - 2016-01-31 11:11 +0100
  Re: Decomposizione LU Antonio Valentino <antonio.valentino@tiscali.it> - 2016-01-31 12:39 +0100

csiph-web