How to resolve the algorithm Arithmetic-geometric mean step by step in the Prolog programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arithmetic-geometric mean step by step in the Prolog programming language
Table of Contents
Problem Statement
Write a function to compute the arithmetic-geometric mean of two numbers.
The arithmetic-geometric mean of two numbers can be (usefully) denoted as
a g m
( a , g )
{\displaystyle \mathrm {agm} (a,g)}
, and is equal to the limit of the sequence: Since the limit of
a
n
−
g
n
{\displaystyle a_{n}-g_{n}}
tends (rapidly) to zero with iterations, this is an efficient method. Demonstrate the function by calculating:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Arithmetic-geometric mean step by step in the Prolog programming language
Source code in the prolog programming language
agm(A,G,A) :- abs(A-G) < 1.0e-15, !.
agm(A,G,Res) :- A1 is (A+G)/2.0, G1 is sqrt(A*G),!, agm(A1,G1,Res).
?- agm(1,1/sqrt(2),Res).
Res = 0.8472130847939792.
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the Perl programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the ERRE programming language
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Perl programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the PHP programming language
You may also check:How to resolve the algorithm Kosaraju step by step in the Java programming language