[ask java] indeks matriks

Pertanyaan umum seputar distribusi Ubuntu yang menjadi distro wajib members ubuntu-indonesia.com
User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

[ask java] indeks matriks

Postby ounowey » 02 Aug 2014, 09:09

kawan programmer java,,saya ada masalah sama indeks matriks nih.
persoalannya begini :
saya punya satu matriks dua dimensi.
saya ingin menghitung jarak(selisih) nilai antar baris dari matriks tersebut pake jarak euclidean distance. setelah didapatkan jaraknya, saya harus memilih jarak yang terkecil.
dua data (baris) dari matriks tersebut(jarak terkecil) akan digabung dengan merata-ratakan bilangan pada masing-masing kolom.
nah masalahnya saya bingung menentukan indeks dari baris keberapa dan keberapa yang mempunyai jarak(selisih) terkecil. bantu saya ya kawan..
menghitung jaraknya udah ok,, menentukan jarak terkecil jg udh ok. nah tinggal menentukan indeks matriks baris ke-i yang belum...
codingnya sy lampirin nih..
User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

Re: [ask java] indeks matriks

Postby ounowey » 02 Aug 2014, 09:12

lha koq ga bisa nglampirin file ya
User avatar
Malsasa
Posts: 2974
Joined: 07 Jun 2010, 22:37
Location: Mojokerto, Indonesia
Contact:

Re: [ask java] indeks matriks

Postby Malsasa » 02 Aug 2014, 11:00

Tidak perlu dilampirkan. Cukup akang ketik di sini dengan tag [ CODE ].
User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

Re: [ask java] indeks matriks

Postby ounowey » 02 Aug 2014, 11:25

[CODE]
public class jarakeuc {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int b,tbar,kol;
double jml,jar,min;

double mat[][]={{3,3,2,3,4,2,3,3,3,3},
{3,2,2,3,3,3,3,3,3,3},
{3,1,2,2,2,2,3,3,3,2},
{4,2,2,3,3,4,4,3,4,4},
{2,2,2,3,2,3,3,3,2,2},
{3,2,3,3,3,3,4,3,4,2},
{3,4,2,3,3,4,4,3,2,4},
{3,2,3,4,3,3,3,4,3,2},
{3,2,2,3,3,3,3,3,3,2},
{4,3,3,4,4,4,4,4,4,4}};
min=100;
for(b=0;b<10;b++){
for(tbar=b+1;tbar<10; tbar++ ) {
jml=0;
for(kol=0;kol<10;kol++){
jml=jml+Math.pow((mat[b][kol]-mat[tbar][kol]),2);
}
jar=Math.sqrt(jml);
System.out.println(jar);
System.out.println("baris ke-"+(b+1));
System.out.println("dan baris ke-"+(tbar+1));
if (jar<min)
min=jar;
else
min=min;
}
}System.out.println("Jarak terkecil="+min);
}
}
/[CODE]
User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

Re: [ask java] indeks matriks

Postby ounowey » 02 Aug 2014, 11:26

Ga ngerti bro,, hehehe..
ya pokonya gitu dah.. saya pngen pas udh diketahui jarak terkecil nya, indeksnya tau juga,,jadi nanti dipake buat ngegabungin dua baris tersebut.
User avatar
ususbuntu
Posts: 199
Joined: 09 Apr 2010, 15:11

Re: [ask java] indeks matriks

Postby ususbuntu » 03 Aug 2014, 09:58

maksudnya menentukan array mana yg paling dekat?

Code: Select all

public class jarakeuc {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int b,tbar,kol;
        double jml,jar,min,poin1 = 0, poin2 = 0;

        double mat[][]={{3,3,2,3,4,2,3,3,3,3},
                        {3,2,2,3,3,3,3,3,3,3},
                        {3,1,2,2,2,2,3,3,3,2},
                        {4,2,2,3,3,4,4,3,4,4},
                        {2,2,2,3,2,3,3,3,2,2},
                        {3,2,3,3,3,3,4,3,4,2},
                        {3,4,2,3,3,4,4,3,2,4},
                        {3,2,3,4,3,3,3,4,3,2},
                        {3,2,2,3,3,3,3,3,3,2},
                        {4,3,3,4,4,4,4,4,4,4}};
        min=100;
        for(b=0;b<10;b++){
            for(tbar=b+1;tbar<10; tbar++ ) {
                jml=0;
                for(kol=0;kol<10;kol++){
                    jml=jml+Math.pow((mat[b][kol]-mat[tbar][kol]),2);
                }
                jar=Math.sqrt(jml);
                System.out.println(jar);
                System.out.println("baris ke-"+(b+1));
                System.out.println("dan baris ke-"+(tbar+1));
                if (jar<min) {
                    min=jar;
                    poin1=b+1;
                    poin2=tbar+1;
                }
                else
                    min=min;
            }
        }
        System.out.println("Jarak terkecil="+min);
        System.out.println("Jarak terdekat "+poin1+" ke "+poin2 );
    }
}



User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

Re: [ask java] indeks matriks

Postby ounowey » 03 Aug 2014, 11:54

iya kang.. cb sy cekk..
User avatar
ounowey
Posts: 30
Joined: 29 Sep 2012, 20:19
Location: karawang, indonesia
Contact:

Re: [ask java] indeks matriks

Postby ounowey » 03 Aug 2014, 12:03

bener euy kang... keren.. hatur nuhun kangggg
User avatar
ususbuntu
Posts: 199
Joined: 09 Apr 2010, 15:11

Re: [ask java] indeks matriks

Postby ususbuntu » 03 Aug 2014, 12:20

sami-sami

Return to “Pertanyaan Umum”

Who is online

Users browsing this forum: mypedoorcette and 2 guests