Penulis membuat program sederhana invers ini. Semoga bermanfaat bagi teman-teman.
import java.io.*;
class invers
{
public static void main(String [] args)throws Exception
{
BufferedReader input=new BufferedReader ( new InputStreamReader (System.in));
float temp;
System.out.println("Ordo matriks=2*2");
float [][] matrika = new float [2][2];
System.out.print("masukan elemen matriksnya: ");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print("elemen ["+(i+1)+","+(j+1)+"]=");
matrika [i][j]=Float.parseFloat (input.readLine());
}
}
for(int i=0;i<2;i++)
{
System.out.print("|");
for(int j=0;j<2;j++)
{
System.out.print(matrika [i][j]+" ");
}
System.out.println("|");
}
float dtr=(matrika[0][0]*matrika[1][1])-(matrika[1][0]*matrika[0][1]);
System.out.println("determinannya="+dtr);
temp=matrika[0][0];
matrika[0][0]=matrika[1][1];
matrika[1][1]=temp;
matrika[0][1]=matrika[0][1]*-1;
matrika[1][0]=matrika[1][0]*-1;
System.out.println("matrik inversnya:");
for(int i=0;i<2;i++)
{
System.out.print("|");
for(int j=0;j<2;j++)
{
System.out.print(matrika [i][j]/dtr+" ");
}
System.out.println("|");
}
}
}
import java.io.*;
class invers
{
public static void main(String [] args)throws Exception
{
BufferedReader input=new BufferedReader ( new InputStreamReader (System.in));
float temp;
System.out.println("Ordo matriks=2*2");
float [][] matrika = new float [2][2];
System.out.print("masukan elemen matriksnya: ");
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
System.out.print("elemen ["+(i+1)+","+(j+1)+"]=");
matrika [i][j]=Float.parseFloat (input.readLine());
}
}
for(int i=0;i<2;i++)
{
System.out.print("|");
for(int j=0;j<2;j++)
{
System.out.print(matrika [i][j]+" ");
}
System.out.println("|");
}
float dtr=(matrika[0][0]*matrika[1][1])-(matrika[1][0]*matrika[0][1]);
System.out.println("determinannya="+dtr);
temp=matrika[0][0];
matrika[0][0]=matrika[1][1];
matrika[1][1]=temp;
matrika[0][1]=matrika[0][1]*-1;
matrika[1][0]=matrika[1][0]*-1;
System.out.println("matrik inversnya:");
for(int i=0;i<2;i++)
{
System.out.print("|");
for(int j=0;j<2;j++)
{
System.out.print(matrika [i][j]/dtr+" ");
}
System.out.println("|");
}
}
}
Tidak ada komentar:
Posting Komentar