miercoles 18 octubre

656 days ago by evalsanjuan

A=matrix(RDF,[[1,20,-1,0.001],[2,-5,20,-0.1],[5,1,-100,-10],[2,-100,-3,1]]); b=vector([1,0,1,0]) 
       
Aa=A.augment(b); show(Aa) 
       

                                
                            

                                
#SIN PIVOTE PARCIAL 
       
Aa[1,:]=Aa[1,:]-2*Aa[0,:]; show(Aa) 
       

                                
                            

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

                                
                            

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

                                
                            

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

                                
                            

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

                                
                            

                                
%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 
       
sp=sustitucion_regresiva(Aa); show(sp) 
       

                                
                            

                                
#CON PIVOTE PARCIAL 
       
A=matrix(RDF,[[1,20,-1,0.001],[2,-5,20,-0.1],[5,1,-100,-10],[2,-100,-3,1]]); b=vector([1,0,1,0]) 
       
Aa=A.augment(b); show(Aa) 
       

                                
                            

                                
Aa.swap_rows(0,2); show(Aa) 
       

                                
                            

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

                                
                            

                                
Aa.swap_rows(1,3); show(Aa) 
       

                                
                            

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

                                
                            

                                
Aa.swap_rows(2,3); show(Aa) 
       

                                
                            

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

                                
                            

                                
cp=sustitucion_regresiva(Aa); show(cp) 
       

                                
                            

                                
show(sp) 
       

                                
                            

                                
show(sp-cp) 
       

                                
                            

                                
%auto def sustitucion_progresiva(L_aumentada): n=L_aumentada.nrows() x=vector(RDF,n) for i in [0,..,(n-1)]: x[i]=L_aumentada[i,n]; for j in [0..i-1]: x[i]=x[i]-L_aumentada[i,j]*x[j] x[i]=x[i]/L_aumentada[i,i] return x 
       
A=matrix(RDF,[[5,2,0,1],[2,-8,-4,0],[1,0,4,-2],[5,0,3,10]]) b=vector(RDF,[1,0,1,0]) D=matrix(RDF,[[5,0,0,0],[0,-8,0,0],[0,0,4,0],[0,0,0,10]]) L=matrix(RDF,[[0,0,0,0],[2,0,0,0],[1,0,0,0],[5,0,3,0]]) U=matrix(RDF,[[0,2,0,1],[0,0,-4,0],[0,0,0,-2],[0,0,0,0]]) 
       
A-D-L-U 
       
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
[0.0 0.0 0.0 0.0]
###JACOBI x0=vector(RDF,[0,0,0,0]) M0=matrix(RDF,[[0.0],[0.0],[0.0],[0.0]]) # Para guardar las soluciones for i in [1..5]: x0=sustitucion_progresiva(D.augment(-(L+U)*x0+b)) M0=M0.augment(x0) # Guardamos x0 html.table( [ [("Paso {pi}".format(pi=k)) for k in [0..5]],[(M0[:,k]) for k in [0..5]]], header = True ) 
       
Paso 0 Paso 1 Paso 2 Paso 3 Paso 4 Paso 5
Paso 0 Paso 1 Paso 2 Paso 3 Paso 4 Paso 5
show(A*x0-b) 
       

                                
                            

                                
###GAUSS-SEIDEL x0=vector(RDF,[0,0,0,0]) M0=matrix(RDF,[[0],[0],[0],[0]]) # AquĆ­ vamos guardando los pasos para mostrarlos al final. for i in [1..5]: x0=sustitucion_progresiva((D+L).augment(-U*x0+b)) M0=M0.augment(x0) # Guardamos las soluciones html.table( [ [("Paso {pi}".format(pi=k)) for k in [0..5]],[(M0[:,k]) for k in [0..5]]], header = True ) 
       
Paso 0 Paso 1 Paso 2 Paso 3 Paso 4 Paso 5
Paso 0 Paso 1 Paso 2 Paso 3 Paso 4 Paso 5
show(A*x0-b) 
       

                                
                            

                                
#####NO LINEAL F(x,y)=(sin(x)-y^2/pi, sin(x*y)) F.diff() 
       
[    (x, y) |--> cos(x)    (x, y) |--> -2*y/pi]
[(x, y) |--> y*cos(x*y) (x, y) |--> x*cos(x*y)]
[    (x, y) |--> cos(x)    (x, y) |--> -2*y/pi]
[(x, y) |--> y*cos(x*y) (x, y) |--> x*cos(x*y)]
x0,y0=2.5,1.0 
       
J0=matrix(RDF,F.diff()(x0,y0)); show(J0) xd1,yd1=J0.solve_right(-F(x0,y0)); xd1,yd1 
       
(0.16456596256002248, 0.23298253387145518)
(0.16456596256002248, 0.23298253387145518)
x1,y1=x0+xd1,y0+yd1 x1,y1 
       
(2.66456596256002, 1.23298253387146)
(2.66456596256002, 1.23298253387146)
J1=matrix(RDF,F.diff()(x1,y1)); show(J1) xd2,yd2=J1.solve_right(-F(x1,y1)); xd2,yd2 
       
(0.034042787931130455, -0.07008407481241519)
(0.034042787931130455, -0.07008407481241519)
x2,y2=x1+xd2,y1+yd2 x2,y2 
       
(2.69860875049115, 1.16289845905904)
(2.69860875049115, 1.16289845905904)
J2=matrix(RDF,F.diff()(x2,y2)); show(J2) xd3,yd3=J2.solve_right(-F(x2,y2)); xd3,yd3 
       
(-0.004709019597881153, 0.0032834773095973924)
(-0.004709019597881153, 0.0032834773095973924)
x3,y3=x2+xd3,y2+yd3 x3,y3 
       
(2.69389973089327, 1.16618193636864)
(2.69389973089327, 1.16618193636864)
implicit_plot(F(x,y)[0]==0,(x,2,3),(y,1,2))+implicit_plot(F(x,y)[1]==0,(x,2,3),(y,1,2),color='red')+points([(x0,y0),(x1,y1),(x2,y2),(x3,y3)],size=20,color='black')