How to resolve the algorithm Gamma function step by step in the Modula-3 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Gamma function step by step in the Modula-3 programming language
Table of Contents
Problem Statement
Implement one algorithm (or more) to compute the Gamma (
Γ
{\displaystyle \Gamma }
) function (in the real field only). If your language has the function as built-in or you know a library which has it, compare your implementation's results with the results of the built-in/library function. The Gamma function can be defined as: This suggests a straightforward (but inefficient) way of computing the
Γ
{\displaystyle \Gamma }
through numerical integration.
Better suggested methods:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Gamma function step by step in the Modula-3 programming language
Source code in the modula-3 programming language
MODULE Gamma EXPORTS Main;
FROM IO IMPORT Put;
FROM Fmt IMPORT Extended, Style;
PROCEDURE Taylor(x: EXTENDED): EXTENDED =
CONST a = ARRAY [0..29] OF EXTENDED {
1.00000000000000000000X0, 0.57721566490153286061X0,
-0.65587807152025388108X0, -0.04200263503409523553X0,
0.16653861138229148950X0, -0.04219773455554433675X0,
-0.00962197152787697356X0, 0.00721894324666309954X0,
-0.00116516759185906511X0, -0.00021524167411495097X0,
0.00012805028238811619X0, -0.00002013485478078824X0,
-0.00000125049348214267X0, 0.00000113302723198170X0,
-0.00000020563384169776X0, 0.00000000611609510448X0,
0.00000000500200764447X0, -0.00000000118127457049X0,
0.00000000010434267117X0, 0.00000000000778226344X0,
-0.00000000000369680562X0, 0.00000000000051003703X0,
-0.00000000000002058326X0, -0.00000000000000534812X0,
0.00000000000000122678X0, -0.00000000000000011813X0,
0.00000000000000000119X0, 0.00000000000000000141X0,
-0.00000000000000000023X0, 0.00000000000000000002X0 };
VAR y := x - 1.0X0;
sum := a[LAST(a)];
BEGIN
FOR i := LAST(a) - 1 TO FIRST(a) BY -1 DO
sum := sum * y + a[i];
END;
RETURN 1.0X0 / sum;
END Taylor;
BEGIN
FOR i := 1 TO 10 DO
Put(Extended(Taylor(FLOAT(i, EXTENDED) / 3.0X0), style := Style.Sci) & "\n");
END;
END Gamma.
You may also check:How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Rust programming language
You may also check:How to resolve the algorithm Wireworld step by step in the Delphi programming language
You may also check:How to resolve the algorithm Knapsack problem/0-1 step by step in the Maple programming language
You may also check:How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Pythagoras tree step by step in the Kotlin programming language