Você está na página 1de 2

Judul Praktikum : Interpolasi Linier dan Kuadratik

Tanggal : 21 Desember 2012



1. Interpolasi Linier
Source code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author red_devil
*/
public class Linier {

public static void main(String[] args) throws IOException {
/**
* @param args the command line arguments
*/
// TODO code application logic here
BufferedReader buf = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("input titik P1 di koordinat x1 : ");
double x1 = Double.parseDouble(buf.readLine());
System.out.print("input titik P1 di koordinat y1 : ");
double y1 = Double.parseDouble(buf.readLine());
System.out.print("input titik P2 di koordinat x2 : ");
double x2 = Double.parseDouble(buf.readLine());
System.out.print("input titik P2 di koordinat y2 : ");
double y2 = Double.parseDouble(buf.readLine());
System.out.print("input Q di koordinat x : ");
double x = Double.parseDouble(buf.readLine());

double y = (((y2 - y1) * (x - x1)) / (x2 - x1)) + y1;

System.out.println("titik Q adalah " + x + "," + y);
}
}

Hasil Running :

Run:
input titik P1 di koordinat x1 : 1
input titik P1 di koordinat y1 : 1.5
input titik P2 di koordinat x2 : 3
input titik P2 di koordinat y2 : 2.5
input Q di koordinat x : 2.1
titik Q adalah 2.1,2.05
BUILD SUCCESSFUL (total time: 1 minute 5 seconds)








2. Interpolasi Kuadratk
Source code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author red_devil
*/
public class Kuadrat {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedReader buf = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("input titik P1 di koordinat x1 : ");
double x1 = Double.parseDouble(buf.readLine());
System.out.print("input titik P1 di koordinat y1 : ");
double y1 = Double.parseDouble(buf.readLine());
System.out.print("input titik P2 di koordinat x2 : ");
double x2 = Double.parseDouble(buf.readLine());
System.out.print("input titik P2 di koordinat y2 : ");
double y2 = Double.parseDouble(buf.readLine());
System.out.print("input titik P3 di koordinat x3 : ");
double x3 = Double.parseDouble(buf.readLine());
System.out.print("input titik P3 di koordinat y3 : ");
double y3 = Double.parseDouble(buf.readLine());
System.out.print("input Q di koordinat x : ");
double x = Double.parseDouble(buf.readLine());

double y = ((y1 * (x - x2) * (x - x3)) / ((x1 - x2) * (x1 - x3))) +
((y2 * (x - x1) * (x - x3)) / ((x2 - x1) * (x2 - x3))) + ((y3 * (x - x1) * (x
- x2)) / ((x3 - x1) * (x3 - x2)));

System.out.println("titik Q adalah " + x + "," + y);
}
}

Hasil Running :

run:
input titik P1 di koordinat x1 : 1
input titik P1 di koordinat y1 : 5
input titik P2 di koordinat x2 : 2
input titik P2 di koordinat y2 : 2
input titik P3 di koordinat x3 : 3
input titik P3 di koordinat y3 : 3
input Q di koordinat x : 2.5
titik Q adalah 2.5,2.0
BUILD SUCCESSFUL (total time: 20 seconds)

Você também pode gostar