Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.python > #7605
| From | Antonio Valentino <antonio.valentino@tiscali.it> |
|---|---|
| Newsgroups | it.comp.lang.python |
| Subject | Re: Decomposizione LU |
| Date | 2016-01-31 12:39 +0100 |
| Organization | Netfront http://www.netfront.net/ |
| Message-ID | <56ADF256.30201@tiscali.it> (permalink) |
| References | <n8kmk6$1lnn$1@gioia.aioe.org> |
Ciao Paolo,
Il 31/01/2016 11:11, Paolo Ferraresi ha scritto:
> 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)
Manca un pezzo.
Nel caso due P non è un amatrice identità.
Prova con:
P, L, U = linalg.lu(A)
z1 = linalg.solve(P,B)
y1 = linalg.solve(L,z1)
x1 = linalg.solve(U,y1)
ciao
--
Antonio Valentino
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Back to it.comp.lang.python | Previous | Next — Previous in thread | Find similar
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