Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.python > #7604
| Path | csiph.com!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Paolo Ferraresi <fp.box@alice.it> |
| Newsgroups | it.comp.lang.python |
| Subject | Decomposizione LU |
| Date | Sun, 31 Jan 2016 11:11:10 +0100 |
| Organization | Aioe.org NNTP Server |
| Lines | 33 |
| Message-ID | <n8kmk6$1lnn$1@gioia.aioe.org> (permalink) |
| NNTP-Posting-Host | 6yGGLgNFLO3yXOroBNm5Ww.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-15; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 |
| X-Mozilla-News-Host | news://news.tin.it:119 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com it.comp.lang.python:7604 |
Show key headers only | 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 | Next — Next 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