Jump to content

Roots of a function: Difference between revisions

m
m (→‎{{header|Sidef}}: updated code)
Line 2,372:
=={{header|Sidef}}==
<lang ruby>func f(x) {
x*x*x - 3*x*x + 2*x;
}
 
 
var step = 0.001;
var start = -1;
var stop = 3;
 
 
for x in range(start+step, stop, step).each { |x|
static sign = false;
given (var value = f(x)) {
when (0) {
say "Root found at #{x}";
}
case (sign && ((value > 0)  != sign)) {
say "Root found near #{x}";
}
}
sign = value>0;
}</lang>
{{out}}
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.