-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSomeFunction.java
More file actions
28 lines (26 loc) · 885 Bytes
/
SomeFunction.java
File metadata and controls
28 lines (26 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.IOException;
import java.lang.Math;
public class SomeFunction {
public static void main(String[] args) throws IOException{
System.out.print("Start of range: ");
double a = EntradaTeclado.leDouble();
System.out.print("End of range: ");
double b = EntradaTeclado.leDouble();
int n = 1;
double c = (a + b) / 2;
for(double fc; (((b - a) / 2) >= 0.0000001) && ((fc = fn(c)) != 0); c = (a + b) / 2){
double fa = fn(a);
if(Math.abs(fc + fa) == (Math.abs(fc) + Math.abs(fa))){
a = c;
}
else{
b = c;
}
n++;
}
System.out.printf("Result: %s\nNumber of iterations: %s\n", c, n);
}
private static double fn(double x){
return ((Math.pow(x, 3) - Math.pow(x, 2)) - (13 * x)) + 8;
}
}