Jumat, 22 April 2011

Designation Numbers with Counting Function Pascal "Function Menghitung Pangkat Bilangan dengan Pascal"

  Agus Nur Ikhsan       Jumat, 22 April 2011
In this article will discuss about how to create a Pascal program to calculate the rank number.
As we know that in Pascal there is no specific function or command to calculate the rank number directly. Thus we have to make own function to compute the rank numbers.
In this discussion will distinguish two types of the rank of a ^ b, that is to b be non-negative integers and a form of real numbers.

For a ^ b with b non-negative integers, of course applies:
a ^ b = a x a x ... x a
with multiplication a number of b times.

If the first case is implemented with Pascal programs, then this case can be solved by iteration. Here is a function to compute the rank of a non-negative integers with Pascal:
view sourceprint?01.pangkatBulat function (a: real, <strong> b: integer </ strong>): real;02.var i: integer; temp: real;03.begin04.temp: = 1;05.for i: = 1 to b do06.begin07.temp: = temp * a;08.end;09.rank: = temp;10.end;

If you look at the function above, then there is the command temp: = temp * a; process is done b times, with initial temp value is 1. Why is that? To answer this we take the example cases. For example, suppose you want to search 3 ^ 4 (a = 3 and b = 4). The result of these powers will be obtained from the multiplication of 3 x 3 x 3 x 3. The following is the calculation process by using algorithms taken from the program above:
view sourceprint?01.temp = 102.
 
03.The first iteration (i = 1)04.temp = temp x a = 1 x 3 = 305.
 
06.The second iteration (i = 2)07.temp = temp x a = 3 x 3 = 908.
 
09.The third iteration (i = 3)10.temp = temp x a = 9 x 3 = 2711.
 
12.fourth iteration (i = 4)13.temp = temp x a = 27 x 3 = 81

Well .. from the results of the above is true that the calculation of 3 ^ 4 = 81. With this algorithm, can be implemented on any values ​​a and b (a and b rounded real non-negative).
Furthermore, what about the b in the form of real numbers? for example 4 ^ 1.5? Hmmm ... if this one can not use because of difficulties in implementing the previous algorithm to form loops. So how?
OK ... to answer this let us remember back in high school lessons on the concept of Ln or Log and exponent. Now we use this concept to our problem Ln. In this case we will find the value of y = a ^ b. Note:
y = a ^ b<=> Ln y = Ln (a ^ b)<=> Y = b Ln Ln (a)<=> E ^ (Ln y) = e ^ (b Ln (a))<=> Y = e ^ (b Ln (a))
From the steps above, we've got a new formulation to find y = a ^ b with b is real. Pascal has been available in the function exp () to find the value of the exponential, and the function Ln () to find the value of logarithm natural number. So that its implementation in Pascal are:
view sourceprint?1.pangkatRiil function (a: real, <strong> b: real </ strong>): real;2.begin3.pangkatRiil: = exp (b * ln (a));4.end;Furthermore, we shall implement the function-function above the Pascal program:
view sourceprint?01.MencariPangkat Program;02.Var x: real, y: integer; z: real;03.
 
04.pangkatBulat function (a: real, b: integer): real;05.var i: integer; temp: real;06.begin07.temp: = 1;08.for i: = 1 to b do09.begin10.temp: = temp * a;11.end;12.rank: = temp;13.end;14.
 
15.pangkatRiil function (a: real, <strong> b: real </ strong>): real;16.begin17.pangkatRiil: = exp (b * ln (a));18.end;19.
 
20.Begin21.x: = 5;22.y: = 3;23.z: is 3.5;24.Write ('Value', x, 'rank', y, 'is',25.pangkatBulat (x, y): 3:0);26.Write ('Value', x, 'rank', z, 'is',27.pangkatRiil (x, z): 3:4);28.End.OK ... hopefully the above explanation can be beneficial.
logoblog

Thanks for reading Designation Numbers with Counting Function Pascal "Function Menghitung Pangkat Bilangan dengan Pascal"

Previous
« Prev Post

Tidak ada komentar:

Posting Komentar