Berikut source kode untuk program biseksi menggunakan bahasa java
package tugas.pkg1;
public class Tugas1
{
public static
double f(double x)
{
return
Math.exp(x)*Math.log(x)-x*x;
}
public static
void main(String[] args)
{
double x =
0, del = 1e-6, a = 1, b = 2;
double dx =
b-a;
int k = 0;
double f;
while
(Math.abs(dx) > del)
{
x=b-(f(b)*(b-a))/(f(b)-f(a));
if
((f(a)*f(x)) < 0)
{
b =
x;
dx =
b-a;
}
else
{
a =
x;
dx =
b-a;
}
k++;
}
System.out.println("Iterasi ke-: " + k);
System.out.println("Nilai Akar: " + x);
System.out.println("error: " + dx);
}
}
|
ConversionConversion EmoticonEmoticon