Roots of a function: Difference between revisions
added Arturo
Drkameleon (talk | contribs) (added Arturo) |
|||
Line 163:
3rd root found at x = 0.0000000000000000000000e 0 (Exactly)
</pre>
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">f: function [n]->
((n^3) - 3*n^2) + 2*n
step: 0.01
start: neg 1.0
stop: 3.0
sign: positive? f start
x: start
while [x =< stop][
value: f x
if? value = 0 ->
print ["root found at" to :string .format:".5f" x]
else ->
if sign <> value > 0 -> print ["root found near" to :string .format:".5f" x]
sign: value > 0
'x + step
]</syntaxhighlight>
{{out}}
<pre>root found near 0.00000
root found near 1.00000
root found near 2.00000</pre>
=={{header|ATS}}==
|