Roots of a function: Difference between revisions

Added Java
(added python)
(Added Java)
Line 153:
... EXACTLY at +1.00000000000000000020, f(x) = -2.168e-19
.... MAY-BE at +1.99999999999999999950, f(x) = -8.674e-19</pre>
 
=={{header|Java}}==
<java>public class Roots{
private static final double epsilon= 1E-10; //error bound, change for more or less accuracy
 
public double f(double x){
return x * x * x - 3 * x * x + 2 * x; //any formula you want here
}
 
public void roots(double lowerBound, double upperBound,
double step){
for(double x= lowerBound;x <= upperBound;x+= step){
double val;
if(Math.abs(val= f(x)) < epsilon){
System.out.println(val);
}
}
}
}</java>
 
=={{header|Maple}}==
Anonymous user