Task

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 

 
1) defining the function:
{def func {lambda {:x} {+ {* 1 :x :x :x} {* -3 :x :x} {* 2 :x}}}}
-> func
 
2) printing roots:
{S.map {lambda {:x}
               {if {< {abs {func :x}} 0.0001} 
                then {br}- a root found at :x else}} 
       {S.serie -1 3 0.01}}
-> 
- a root found at 7.528699885739343e-16                                                                                                    
- a root found at 1.0000000000000013                                                                                                    
- a root found at 2.000000000000002                                                                                                    
 
3) printing the roots of the "sin" function between -720° to +720°;
 
{S.map {lambda {:x}
               {if {< {abs {sin {* {/ {PI} 180} :x}}} 0.01}
                then {br}- a root found at :x° else}} 
       {S.serie -720 +720 10}}
-> 
- a root found at -720°                  
- a root found at -540°                  
- a root found at -360°                  
- a root found at -180°                  
- a root found at 0°                  
- a root found at 180°                  
- a root found at 360°                  
- a root found at 540°                  
- a root found at 720°
 