How to resolve the algorithm Nth root step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Nth root step by step in the Racket programming language
Table of Contents
Problem Statement
Implement the algorithm to compute the principal nth root
A
n
{\displaystyle {\sqrt[{n}]{A}}}
of a positive real number A, as explained at the Wikipedia page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Nth root step by step in the Racket programming language
Source code in the racket programming language
#lang racket
(define (nth-root number root (tolerance 0.001))
(define (acceptable? next current)
(< (abs (- next current)) tolerance))
(define (improve current)
(/ (+ (* (- root 1) current) (/ number (expt current (- root 1)))) root))
(define (loop current)
(define next-guess (improve current))
(if (acceptable? next-guess current)
next-guess
(loop next-guess)))
(loop 1.0))
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Mouse position step by step in the Delphi programming language
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Visual FoxPro programming language
You may also check:How to resolve the algorithm Inheritance/Single step by step in the ChucK programming language
You may also check:How to resolve the algorithm Soundex step by step in the Racket programming language