Ayo bergabung di Komunitas Online Shop terbesar di Indonesia
>> 9.29.2012
Berbagi Informasi di Dunia Tanpa Batas
|
Sekilas tentang Metode Newton-Raphson dari Wikipedia:
In numerical analysis, Newton's method (also known as the Newton–Raphson method), named after Isaac Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. The algorithm is first in the class of Householder's methods, succeeded by Halley's method. The method can also be extended to complex functions and to systems of equations.
Untuk belajar tentang metode newton-raphson lebih dalam bisa di lihat disini http://numericalmethods.eng.usf.edu/topics/newton_raphson.html
Berikut ini kodingnya :
import java.util.*;
public class Newton{
public static Scanner sc = new Scanner(System.in);
public static double[] A;
public static double[] B;
public static double relApproxErrorLimit;
public static double Finitial(double x) {
double retVal = 0.0;
for (int i = A.length - 1; i >= 0; i--)
retVal += A[i] * Math.pow(x, i);
return retVal;
}
public static double Fder(double x) {
double retVal2 = 0.0;
for (int i = B.length - 1; i >= 0; i--)
retVal2 += B[i] * Math.pow(x, i);
return retVal2;
}
public static void printTableLine() {
for(int i = 0; i < 78; i++)
System.out.print('-');
System.out.println();
}
public static void findRoot(double Sval) {
double xnew =0.0;
double xold =0.0;
double prevApprox = 0.0;
int count = 0;
printTableLine();
System.out.printf("%10s %10s %10s %10s %10s \n", "Iterasi","x", "F(x)", "F'(x)", "% Galat");
printTableLine();
while (true) {
count++;
System.out.printf("%10d %10f %10f %10f ", count, Sval, Finitial(Sval),Fder(Sval));
xnew = Sval - Finitial(Sval) / Fder(Sval);
xold = Sval;
Sval = xnew;
System.out.printf("%10f \n", Math.abs((xnew - xold) / xnew * 100.0));
if (count > 1)
if (Math.abs((xnew - xold) / xnew * 100.0) < relApproxErrorLimit)
break;
if (count % 50 == 0) {
System.out.println();
System.out.println(" #" + count + " Iterasi Telah Dilakukan.");
System.out.println(" #Ketik 't' Untuk Menghentikan Iterasi.");
System.out.println(" #Ketik Selain 't' Untuk Melanjutkan Iterasi.");
System.out.println();
System.out.print("Lanjutkan? ");
String s = sc.next();
if (s.equals("T") || s.equals("t"))
break;
System.out.println();
}
}
printTableLine();
System.out.println();
System.out.println("\t Jumlah Iterasi : " + count);
System.out.println("\tBatas % Galat Relatif : " + relApproxErrorLimit);
System.out.println("\t Hampiran Akar : " + xnew);
System.out.println();
}
public static void main(String[] args) {
int N, M,O;
double Svalue;
while (true) {
System.out.print("Derajat Polinomial F(x) : ");
N = sc.nextInt();
System.out.println();
if (N >= 1)
break;
else {
System.out.println(" #Derajat Polinomial Harus > 0 !");
System.out.println();
}
}
System.out.println();
A = new double[N + 1];
for (int i = N; i >= 0; i--) {
System.out.print("Koefisien Derajat " + i + " : ");
A[i] = sc.nextDouble();
}
System.out.println();
while (true) {
System.out.print("Derajat Polinomial Turunan F(x) : ");
O = sc.nextInt();
System.out.println();
if (O >= 1)
break;
else {
System.out.println(" #Derajat Polinomial Harus > 0 !");
System.out.println();
}
}
System.out.println();
B = new double[O + 1];
for (int i = O; i >= 0; i--) {
System.out.print("Koefisien Derajat " + i + " : ");
B[i] = sc.nextDouble();
}
System.out.println();
while (true) {
System.out.print("Nilai awal (X0): ");
Svalue = sc.nextDouble();
System.out.println();
if (Svalue>0.0)
break;
else
{
System.out.println("Nilai awal harus lebih dari 0 !");
}
}
while (true) {
System.out.print("Digit Signifikan : ");
M = sc.nextInt();
System.out.println();
if (M >= 1)
break;
else {
System.out.println(" #Jumlah Digit Signifikan Harus > 0 !");
System.out.println();
}
}
relApproxErrorLimit = 0.5 * Math.pow(10, 2 - M);
System.out.println();
findRoot(Svalue);
}
}
A. Kegagalan sistem perekonomian dunia saat ini
Director:
Andrew Stanton
Writers:
Andrew Stanton (original story), Pete Docter (original story), and 2 more credits »
Stars:
Ben Burtt, Elissa Knight and Jeff Garlin
Glimpse of the storyline:
1. boil water
1.1 fill kettle
1.2 put kettle on stove
1.3 turn on & light gas
1.4 wait for kettle to boil
1.5 turn off gas
2. empty pot
3. make pot
3.1 warm pot
3.2 put tea leaves in pot
3.3 pour in boiling water
4. wait 4 or 5 minutes
5. pour tea
5.1 put milk in cup
5.2 fill cup with tea
5.3 do sugar
5.3.1 ask guest about sugar
5.3.2 add sugar to taste
Plan 0 :
do 1
at the same time,if the pot is full 2
then 3. -4
after 4/5 minutes do 5
Plan 1 :
do 1.1 – 1.2 – 1.3 – 1.4.
when kettle boils do 1.5 .
Plan 3 :
do 3.1 – 3.2 – 3.3
Plan 5 :
if the cup is empty then
do 5.1 – 5.2
else
do 5.3
Plan 5.3 :
do 5.3.1,
if guest want sugar do 5.3.2
© Free Blogger Templates Skyblue by Ourblogtemplates.com 2008
Back to TOP