AmpMat_ejercicio 2b sistemas

hace 353 días por evalsanjuan

A=matrix(RDF,[[5,1,-100,-10],[2,-5,20,-0.1],[1,20,-1,0.001],[2,-100,-3,1]]);A 
       
[   5.0    1.0 -100.0  -10.0]
[   2.0   -5.0   20.0   -0.1]
[   1.0   20.0   -1.0  0.001]
[   2.0 -100.0   -3.0    1.0]
[   5.0    1.0 -100.0  -10.0]
[   2.0   -5.0   20.0   -0.1]
[   1.0   20.0   -1.0  0.001]
[   2.0 -100.0   -3.0    1.0]
b=vector([1,0,1,0]);b Aa=A.augment(b);Aa 
       
[   5.0    1.0 -100.0  -10.0    1.0]
[   2.0   -5.0   20.0   -0.1    0.0]
[   1.0   20.0   -1.0  0.001    1.0]
[   2.0 -100.0   -3.0    1.0    0.0]
[   5.0    1.0 -100.0  -10.0    1.0]
[   2.0   -5.0   20.0   -0.1    0.0]
[   1.0   20.0   -1.0  0.001    1.0]
[   2.0 -100.0   -3.0    1.0    0.0]
Aa[1,:]=Aa[1,:]-Aa[1,0]/Aa[0,0]*Aa[0,:] Aa[2,:]=Aa[2,:]-Aa[2,0]/Aa[0,0]*Aa[0,:] Aa[3,:]=Aa[3,:]-Aa[3,0]/Aa[0,0]*Aa[0,:] show(Aa) 
       

                                
                            

                                
Aa.swap_rows(1,3); Aa 
       
[   5.0    1.0 -100.0  -10.0    1.0]
[   0.0 -100.4   37.0    5.0   -0.4]
[   0.0   19.8   19.0  2.001    0.8]
[   0.0   -5.4   60.0    3.9   -0.4]
[   5.0    1.0 -100.0  -10.0    1.0]
[   0.0 -100.4   37.0    5.0   -0.4]
[   0.0   19.8   19.0  2.001    0.8]
[   0.0   -5.4   60.0    3.9   -0.4]
Aa[2,:]=Aa[2,:]-Aa[2,1]/Aa[1,1]*Aa[1,:] Aa[3,:]=Aa[3,:]-Aa[3,1]/Aa[1,1]*Aa[1,:] show(Aa) 
       

                                
                            

                                
Aa.swap_rows(2,3) Aa[3,:]=Aa[3,:]-Aa[3,2]/Aa[2,2]*Aa[2,:] show(Aa) 
       

                                
                            

                                
 
       
x4=Aa[3,4]/Aa[3,3]; x4 
       
0.665672766729452
0.665672766729452
show(sustitucion_regresiva(Aa)) 
       

                                
                            

                                
 
       
%auto def sustitucion_regresiva(U_aumentada): n=U_aumentada.nrows() x=vector(RDF,n) for i in [(n-1),(n-2)..0]: x[i]=U_aumentada[i,n]; for j in [i+1..n-1]: x[i]=x[i]-U_aumentada[i,j]*x[j] x[i]=x[i]/U_aumentada[i,i] return x 
       
show(sustitucion_regresiva(Aa)) 
       

                                
                            

                                
A.solve_right(b) 
       
(0.5603417686842272, 0.019256601476663335, -0.04791385121600763,
0.6612350566498563)
(0.5603417686842272, 0.019256601476663335, -0.04791385121600763, 0.6612350566498563)
#sin pivote 
       
A=matrix(RDF,[[1,20,-1,0.001],[2,-5,20,-0.1],[5,1,-100,-10],[2,-100,-3,1]]);A 
       
[   1.0   20.0   -1.0  0.001]
[   2.0   -5.0   20.0   -0.1]
[   5.0    1.0 -100.0  -10.0]
[   2.0 -100.0   -3.0    1.0]
[   1.0   20.0   -1.0  0.001]
[   2.0   -5.0   20.0   -0.1]
[   5.0    1.0 -100.0  -10.0]
[   2.0 -100.0   -3.0    1.0]
b=vector([1,0,1,0]) 
       
Aa=A.augment(b) 
       
Aa 
       
[   1.0   20.0   -1.0  0.001    1.0]
[   2.0   -5.0   20.0   -0.1    0.0]
[   5.0    1.0 -100.0  -10.0    1.0]
[   2.0 -100.0   -3.0    1.0    0.0]
[   1.0   20.0   -1.0  0.001    1.0]
[   2.0   -5.0   20.0   -0.1    0.0]
[   5.0    1.0 -100.0  -10.0    1.0]
[   2.0 -100.0   -3.0    1.0    0.0]
Aa[1,:] 
       
[ 2.0 -5.0 20.0 -0.1  0.0]
[ 2.0 -5.0 20.0 -0.1  0.0]
Aa[1,:]=Aa[1,:]-2*Aa[0,:] Aa[2,:]=Aa[2,:]-5*Aa[0,:] Aa[3,:]=Aa[3,:]-2*Aa[0,:] show(Aa) 
       

                                
                            

                                
Aa[2,:]=Aa[2,:]-Aa[2,1]/Aa[1,1]*Aa[1,:] Aa[3,:]=Aa[3,:]-Aa[3,1]/Aa[1,1]*Aa[1,:] show(Aa) 
       

                                
                            

                                
Aa[3,:]=Aa[3,:]-Aa[3,2]/Aa[2,2]*Aa[2,:] show(Aa) 
       

                                
                            

                                
show(sustitucion_regresiva(Aa))