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 to findfinds the roots of a specific function. : x^3 - 3*x^2 + 2*x */
parse arg bot top inc . /*allowobtain useroptional toarguments specifyfrom options.the CL*/
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 all the values specified.*/
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. for the next time. */
end /*j*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────F function──────────────────────────function────────────────────────────────*/
f: procedure; parse arg x; return x**3 - 3 * x**2 + 2 * x</lang>
'''output''' &nbsp; when using the defaults for input:
<pre>
found a root at 0