Roots of a function: Difference between revisions
Content added Content deleted
(Added Elixir) |
m (→as-is function: added/changed whitespace and comments.) |
||
Line 1,934:
=={{header|REXX}}==
===as-is function===
<lang rexx>/*REXX program
parse arg bot top inc . /*
if bot=='' | bot==',' then bot=-3 /*Not specified? Then use the default.*/
if top=='' | top==',' then top=+3 /* " " " " " " */
if inc=='' | inc==',' then inc=.0001 /* " " " " " " */
z=f(bot); !=sign(z)
do j=bot to top by inc /*traipse through
z=f(j); $=sign(z) /*compute the new value and the sign.*/
if z=0 then say 'found a root at' j/1
else if !\==$ then if !\==0 then say 'passed a root at' j/1
!=$ /*use the new sign
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────F
f: procedure; parse arg x; return x**3 - 3 * x**2 + 2 * x</lang>
'''output''' when using the defaults for input:
<pre>
found a root at 0
|