Interpolasi Kubik

Posted on Updated on

ini ada source code java yang sederhana mengenai interpolasi kubik:

import javax.swing.*;

class interpolasikubik{
public static void main (String args []){
double x[]={1,2,3,4,5,6,7,8,9,10};
double y[]={1.23,3.45,9.19,1.92,4.56,2.00,-4.88,7.77,3.33,2.34};
double  z=4.321;
double nilaiZ;
int a=0,b=0,c=0, d=0;
for (int q=0;q<x.length;q+=3)
{
if(x[q]>z)
{
a=q-3;
b=q-2;
c=q-1;
d=q;
break;
}
}
System.out.println(“=================”);
System.out.println(“INTERPOLASI CUBIC”);
System.out.println(“=================”);
System.out.print(“Nilai yang dicari adalah “+z+”\n”);
System.out.print(“Nilai yang x dipakai adalah “+(int)x[a]+”, “+(int)x[b]+”, “+(int)x[c]+” , “+(int)x[d]+”\n”);
nilaiZ=((y[a]*(z-x[b])*(z-x[c])*(z-x[d]))/((x[a]-x[b])*(x[a]-x[c])*(x[a]-x[d])))+ ((y[b]*(z-x[a])*(z-x[c])*(z-x[d]))/((x[b]-x[a])*(x[b]-x[c])*(x[b]-x[d])))+((y[c]*(z-x[a])*(z-x[b])*(z-x[d]))/((x[c]-x[a])*(x[c]-x[b])*(x[c]-x[d])))+((y[d]*(z-x[a])*(z-x[b])*(z-x[c]))/((x[d]-x[a])*(x[d]-x[b])*(x[d]-x[c])));
System.out.println(“nilai f(x) dari x= “+z+” adalah “+ nilaiZ);

}
}

Terima Kasih Sudah berkunjung ke Blog saya. Dan Jangan Lupa Isi Komentar di Bawah ini.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s