Best Rapidshare Search
1. bagi dua
import java.text.DecimalFormat;
class metnum{
DecimalFormat set = new DecimalFormat("0.000000000");
double a=1,b=2,c,fa,fb,fc;
double fungsi(double x){
return x*x*x + 2*x*x + 10*x - 20;
}
void proses(){
System.out.println("i\t\ta\t\tb\t\tc\t\tfa\t\tfb\t\tfc");
System.out.println("------------------------------------------------------------------------------------------------------");
for(int i=1;i<=29;i++){
fa=fungsi(a);
fb=fungsi(b);
c=(a+b)/2;
fc=fungsi(c);
System.out.println(i+"\t"+set.format(a)+"\t"+set.format(b)+"\t"+set.format(c)+"\t"+set.format(fa)+"\t"+set.format(fb)+"\t"+set.format(fc));
if(fa*fc > 0)
a=c;
else
b=c;
}
}
}
public class bagiDua {
public static void main(String[] args) {
metnum m = new metnum();
m.proses();
}
}
2. (versi Gue))
package programmatnum;
import java.text.DecimalFormat;
public class Main {
static double fx(double x){
double fx;
fx = (1*Math.pow(x,3))+(2*Math.pow(x,2))+ (10*Math.pow(x,1))-20;
return fx;
}
public static void main(String[] args) {
DecimalFormat df=new DecimalFormat("0.0000000000");
int i;
double x=0.00000001;
double y=0.00000001;
double a,b,c;
double fa,fb,fc,faxfc;
System.out.println("------------------------------------------------------------------------------------");
System.out.println("i a\t\tb \tc \tfa \tfb \tfc\tfaxfc");
System.out.println("------------------------------------------------------------------------------------");
a=1; b=2;c=0;
i=0;
fc=0;
while ((Math.abs(a-b)>x)||(fc>y)){
c=(a+b)/2;
fa=fx(a);fb=fx(b);fc=fx(c);
faxfc=fa*fc;
System.out.println(i+" "+df.format(a)+" "+ df.format(b)+" "+ df.format(c)+" "+df.format(fa)+
" "+ df.format(fb)+" "+ df.format(fc)+" " + df.format(faxfc)+" ");
if((fa*fc)<0 br="br"> {
b=c;
}
else
{
a=c;
}
i++;
}
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("Hampiran Akar = " + df.format(c));
}
}0>
Tahun 1225 Leonardo da Pisa mencari akar persamaan
Dan menemukan x=1.368808107.
tidak seorangpun yang mengetahui cara Leonardo menemukan
nilai ini. Tapi sekarang rahasia itu telah terbongkar.
Dan kamu jadilah salah satu dari orang yang mengetahui
rahasia itu !
ket :
- silahkan pilih metode antara BAGI DUA atau REGULA FALSI
- dikerjakan pake manual ato program
- jika program maka gunakan bahasa java, silahkan cetak source code pada kertas A4 beserta print screen hasil outputnya.
- jika manual kerjakan di kertas HVS/Folio bergaris
- dikumpulkan minggu depan
1. bagi dua
import java.text.DecimalFormat;
class metnum{
DecimalFormat set = new DecimalFormat("0.000000000");
double a=1,b=2,c,fa,fb,fc;
double fungsi(double x){
return x*x*x + 2*x*x + 10*x - 20;
}
void proses(){
System.out.println("i\t\ta\t\tb\t\tc\t\tfa\t\tfb\t\tfc");
System.out.println("------------------------------------------------------------------------------------------------------");
for(int i=1;i<=29;i++){
fa=fungsi(a);
fb=fungsi(b);
c=(a+b)/2;
fc=fungsi(c);
System.out.println(i+"\t"+set.format(a)+"\t"+set.format(b)+"\t"+set.format(c)+"\t"+set.format(fa)+"\t"+set.format(fb)+"\t"+set.format(fc));
if(fa*fc > 0)
a=c;
else
b=c;
}
}
}
public class bagiDua {
public static void main(String[] args) {
metnum m = new metnum();
m.proses();
}
}
2. (versi Gue))
package programmatnum;
import java.text.DecimalFormat;
public class Main {
static double fx(double x){
double fx;
fx = (1*Math.pow(x,3))+(2*Math.pow(x,2))+ (10*Math.pow(x,1))-20;
return fx;
}
public static void main(String[] args) {
DecimalFormat df=new DecimalFormat("0.0000000000");
int i;
double x=0.00000001;
double y=0.00000001;
double a,b,c;
double fa,fb,fc,faxfc;
System.out.println("------------------------------------------------------------------------------------");
System.out.println("i a\t\tb \tc \tfa \tfb \tfc\tfaxfc");
System.out.println("------------------------------------------------------------------------------------");
a=1; b=2;c=0;
i=0;
fc=0;
while ((Math.abs(a-b)>x)||(fc>y)){
c=(a+b)/2;
fa=fx(a);fb=fx(b);fc=fx(c);
faxfc=fa*fc;
System.out.println(i+" "+df.format(a)+" "+ df.format(b)+" "+ df.format(c)+" "+df.format(fa)+
" "+ df.format(fb)+" "+ df.format(fc)+" " + df.format(faxfc)+" ");
if((fa*fc)<0 br="br"> {
b=c;
}
else
{
a=c;
}
i++;
}
System.out.println("------------------------------------------------------------------------------------------");
System.out.println("Hampiran Akar = " + df.format(c));
}
}0>
0 komentar:
Post a Comment