import java.applet.*;
import java.awt.*;
public class Example2_9 extends Applet
{ public static boolean LU(double[][] a,int n)
{ int i,j,k;
if (a[0][0]==0)return false;
for(i=1;i for(i=1;i { for(k=0;k if(a[k][k]==0)return false;
for(j=i+1;j { for(k=0;k for(k=0;k a[j][i]/=a[i][i];
}
}
return true;
}
public void paint(Graphics g)
{double[][] a={{2,4,4,2},{3,3,12,6},{2,4,-1,2},{4,2,1,1}};
double[][] l=new double[4][4];
int i,j;
if(LU(a,4))
{for(i=0;i {for(j=0;j l[i][i]=1;}
g.drawString("下三角L为:",10,20);
g.drawString(""+l[0][0]+" "+l[0][1]+" "+l[0][2]+" "+l[0][3],10,40);
g.drawString(""+l[1][0]+" "+l[1][1]+" "+l[1][2]+" "+l[1][3],10,60);
g.drawString(""+l[2][0]+" "+l[2][1]+" "+l[2][2]+" "+l[2][3],10,80);
g.drawString(""+l[3][0]+" "+l[3][1]+" "+l[3][2]+" "+l[3][3],10,100);
g.drawString("上三角U为:",10,120);
g.drawString(""+a[0][0]+" "+a[0][1]+" "+a[0][2]+" "+a[0][3],10,140);
g.drawString(""+a[1][0]+" "+a[1][1]+" "+a[1][2]+" "+a[1][3],10,160);
g.drawString(""+a[2][0]+" "+a[2][1]+" "+a[2][2]+" "+a[2][3],10,180);
g.drawString(""+a[3][0]+" "+a[3][1]+" "+a[3][2]+" "+a[3][3],10,200);}
else g.drawString("矩阵无法分解",10,20);
}
}