How to resolve the algorithm Roots of a function step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Roots of a function step by step in the Arturo programming language

Table of Contents

Problem Statement

Create a program that finds and outputs the roots of a given function, range and (if applicable) step width.
The program should identify whether the root is exact or approximate.

For this task, use:     ƒ(x)   =   x3 - 3x2 + 2x

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Roots of a function step by step in the Arturo programming language

Source code in the arturo programming language

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
]


  

You may also check:How to resolve the algorithm Generator/Exponential step by step in the R programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Fortran programming language
You may also check:How to resolve the algorithm Cantor set step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the OCaml programming language