Roots of a function: Difference between revisions

no edit summary
No edit summary
Line 4:
 
=={{header|Ada}}==
<lang ada>with Ada.Text_Io; use Ada.Text_Io;
procedure Roots_Of_Function is
Line 42:
X := X + Step;
end loop;
end Roots_Of_Function;</adalang>
 
=={{header|ALGOL 68}}==
Line 125:
 
=={{header|C++}}==
<lang cpp>#include <iostream>
 
double f(double x)
Line 160:
sign = ( value > 0 );
}
}</cpplang>
 
=={{header|D}}==
<lang d>module findroot ;
import std.stdio ;
import std.math ;
Line 226:
void main(){
findroot(&f, -1.0L, 3.0L, 0.001L).report(&f) ;
}</dlang>
 
Output ( NB:smallest increment for real type in D is real.epsilon = 1.0842e-19 ):
Line 301:
 
=={{header|Java}}==
<lang java>public class Roots{
private static final double epsilon= 1E-10; //error bound, change for more or less accuracy
 
Line 317:
}
}
}</javalang>
 
=={{header|Maple}}==
Line 367:
 
=={{header|Perl}}==
<lang perl>sub f
{
my $x = shift;
Line 403:
# Update our sign
$sign = ( $value > 0 );
}</perllang>
 
 
=={{header|Python}}==
From Perl:
<lang python>f = lambda x: x * x * x - 3 * x * x + 2 * x
 
step = 0.001 # Smaller step values produce more accurate and precise results
Line 430:
sign = value > 0
 
x += step</pythonlang>