Anonymous user
Roots of a function: Difference between revisions
m
→{{header|REXX}}: changed wording in the REXX section header, added whitespace, used a template for an output section.
m (→{{header|Julia}}: Updated for Julia 1.3) |
m (→{{header|REXX}}: changed wording in the REXX section header, added whitespace, used a template for an output section.) |
||
Line 2,590:
=={{header|REXX}}==
Both of these REXX versions use the '''bisection method'''
===function
<lang rexx>/*REXX program finds the roots of a specific function: x^3 - 3*x^2 + 2*x via bisection*/
parse arg bot top inc . /*obtain optional arguments from the CL*/
Line 2,597:
if top=='' | top=="," then top= +5 /* " " " " " " */
if inc=='' | inc=="," then inc= .0001 /* " " " " " " */
z= f(bot - inc)
!= sign(z) /*obtain the sign of the initial value.*/
do j=bot to top by inc
z= f(j); $= sign(z)
if z=0 then
else if
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
f:
/*with factoring ──► x{ x^2 -3x + 2 } */
/*more " ──► x{ x( x-3 ) + 2 } */</lang>
<pre>
found an exact root at 0
Line 2,617:
</pre>
===function
This version is about 40% faster than the 1<sup>st</sup> REXX version.
<lang rexx>/*REXX program finds the roots of a specific function: x^3 - 3*x^2 + 2*x via bisection*/
Line 2,624:
if top=='' | top=="," then top= +5 /* " " " " " " */
if inc=='' | inc=="," then inc= .0001 /* " " " " " " */
x= bot -
z= x * (x * (x-3) + 2)
!= sign(z)
{{out|output|text= is the same as the 1<sup>st</sup> REXX version.}} <br><br>
|