Calculus of functions ( calculations ) in PHP

Calculus ( calculation) does not seem to get away from computer programming , and vice versa . It seems impossible to a computer programming can be "live " without the calculus contained therein .
The calculus has a set of functions available in PHP programming . But before further studied the calculus functions in PHP , will first be given a list of the constants needed in calculus calculations . Here are the constants .


Constant Value Information
M_PI 3.14159265358979323846 Pi , which is generally used in calculating the area of a circle . ** )
M_E 2.7182818284590452354 e , or also known as natural numbers .
M_LOG2E 1.4426950408889634074 2log e , or logarithm base e with number 2 .
M_LOG10E 0.43429448190325182765 log e , or logarithm e.
M_LN2 0.69314718055994530942 ln 2 , or the natural logarithm 2 .
M_LN10 2.30258509299404568402 ln 10 , or the natural logarithm 10
M_PI_2 1.57079632679489661923 pi / 2
M_PI_4 0.78539816339744830962 pi / 4
M_1_PI 0.31830988618379067154 1/pi
M_2_PI 0.63661977236758134308 2/pi
M_SQRTPI 1.77245385090551602729 The root of pi * )
M_2_SQRTPI 1.12837916709551257390 2/akar pi
M_SQRT2 1.41421356237309504880 Roots 2
M_SQRT3 1.73205080756887729352 The root of 3 * )
M_SQRT1_2 0.70710678118654752440 1/akar 2
M_LNPI 1.14472988584940017414 ln pi * )
M_EULER 0.57721566490153286061 Euler's constant * )
Only M_PI is contained in all versions of PHP . Another new constants that are on PHP version 4.0.0 , whereas those marked * ) are new in version 4.0.2 and above.
Well , now let's discuss calculus functions in PHP . Broadly speaking calculus functions in PHP can be divided into several groups:

  • Trig functions
  • The ranks and functions Logarithmic
  • Base functions n
  • Other Functions
Trig functions
trigonometric functions are functions that relate to the science of trigonometry , the science of the angles of a triangle. These functions are:
  • sin (angle ) , takes the sine of a corner .
  • cos (angle ) , takes the cosine of an angle .
  • tan (angle ) , takes the tangent of a corner .
  • salty (angle ) , taking the value of arcus sine an angle.
  • ACOs (angle ) , takes the arcus cosine of an angle .
  • atan (angle ) , taking the arcus tangent value of an angle .
  • deg2rad ( x ) , convert degrees to radians .
  • rad2deg ( x ) , convert radians to degrees.
The angle value to be processed must be expressed in radians .
Here is the usage of these functions in PHP programming .



Trigonometric Functions < / TITLE >
< / HEAD >
In a triangle, one leg of the angle is 45 °

$ A = deg2rad ( 45 ) ;
echo " In radians , 45 ° is $ a radians .
" ;
$ x = sin ( $ a ) ;
$ y = cos ( $ a ) ;
$ z = tan ( $ a ) ;
echo " sin ( $ a ) = $ x
";
echo " cos ( $ a ) = $ y
";
echo " tan ( $ a ) = $ z
";
$ p = salt ( $ x ) ;
$ q = ACOs ( $ y ) ;
$ r = atan ( $ z ) ;
echo " If the TSB values returned to radians :
";
echo " sauce ( $ x ) = $ p
";
echo " ACOs ( $ y ) = $ q
";
echo " atan ( $ z ) = $ r
";
?>
< / BODY >
< / HTML >

The ranks and functions Logarithmic
These functions are used to rank and logarithm calculations associated with the rank and logarithms . These functions are:
  • pow ( $ x , $ y ) , is used to raise to $ x by $ y.
  • exp ( $ x ) , used to promote e by $ x.
  • log ( $ x ) , is used to retrieve the log naturalists $ x.
  • log10 ( $ x ) , is used to retrieve the log $ x.
  • sqrt ( $ x ) , used to find the root of $ x.
Worth noting that it was written by naturalist logarithm log ( ) , while for ordinary logarithms written by log10 . Sample usage is as follows :



rank and Logarithmic Functions < / TITLE >
< / HEAD >
$ A = pow ( 2.10 ) ;
$ B = exp ( 2 ) ;
$ c = log ( 10 ) ;
$ d = log10 ( 10 ) ;
$ E = sqrt ( 100 ) ;
echo " second rank of 10 = $ a
";
echo " e rank 2 = $ b
";
echo " ln 10 = $ c
";
echo "log 10 = $ d
";
echo " root of 100 = $ e " ;
?>
< / BODY >
< / HTML >
Suppose if we want to take the logarithm to base e or 10 numbers in addition ? We can take advantage of the law contained in the logarithm as follows :
alog b = ( plog b ) / ( plog a) ( equation 1 )
The value of p is free .
Because the p value free, then it should be replaced with a value of 10 , because if 10 is used as the logarithm base does not need to be written in the equation , so that equation 1 can be written as follows :
alog b = (log b ) / (log a) ( equation 2 )
Or you can also log naturalist :
alog b = ( ln b ) / ( ln a) ( equation 3 )
Examples of legal usage in the PHP script is as follows :


rank and Logarithmic Functions < / TITLE >
< / HEAD >
$ A = log ( 4 ) / log ( 2 ) ;
echo " 2 log 4 = " ;
echo $ a ;
?>
< / BODY >
< / HTML >

Base functions n
Base functions n used to convert a number to the number of base n. These functions are:
base_convert ( x , y , z ) , which converts the number x of y based based to z.

  • decbin ( x ) , which converts the base-10 numbers into base 2 .
  • dechex ( x ) , which converts the base-10 numbers into base 16 .
  • decoct ( x ) , which converts the base-10 numbers into base 8 .
  • bindec ( ) , which converts the base 2 numbers into base 10 .
  • hexdec ( ) , which converts the numbers into base 16 base 10 .
  • octdect ( ) , which converts the numbers into base 10 base 8 .
Example :


Base Function n < / TITLE >
< / HEAD >

$ A = 73 ;
$ B = base_convert ( $ a , 10.3 ) ;
$ c = decbin ( $ a ) ;
$ d = dechex ( $ a ) ;
$ E = decoct ( $ a ) ;
echo " $ a in Figure 3 is the base number = $ b
";
echo "Number $ a in the base number 2 is = $ c
";
echo "Number $ a in the base number 16 is = $ d
";
echo "Number $ a in the base number 8 is = $ e
";
?>
< / BODY >
< / HTML >

Other calculus functions
Several other known function of PHP calculus is:

  • abs ( x ) , taking the absolute value of x.
  • ceil ( x ) , round out a fraction x to the top .
  • floor ( x ) , round out a fraction x to the bottom.
  • round ( x , y ) , round out a fraction x to y digits behind the comma .
  • pi ( ) , taking the value of pi , which is approximately equal to 3.14159265358979323846 or M_PI constants .
  • number_format ( x , y , k , r ) , write the number x of y format decimal places , with the comma is replaced with k characters and thousands separator characters replaced by r.
Example :


Other < / TITLE >
< / HEAD >

$ A = 5 ;
$ B = -5 ;
$ c = abs ( $ a ) ;
$ d = abs ( $ b ) ;
echo " abs ( 5 ) = abs ( -5 ) = $ c
";
$ E = ceil ( 4:25 ) ;
echo " ceil ( 4:25 ) = $ e
";
$ f = floor ( 4:25 ) ;
echo " floor ( 4:25 ) = $ f
";
$ g = round ( 3.6) ;
echo "round ( 3.6) = $ g
";
$ h = round ( 3.5853 , 2 ) ;
echo "round ( 3.5853 , 2 ) = $ h ";
echo " (up to two digits behind the comma )
";
$ pi = pi () ;
echo " Value is pi = $ pi
";
$ format1 = number_format ( 1234567.890 ) ;
$ format2 = number_format ( 1234567.890,3 ) ;
$ format3 = number_format ( 1234567.890,3 ,'/','*');
echo " Format of numbers in PHP =
";
echo " Format 1 = $ format1
";
echo " Format 2 = $ format2
";
echo " Format 3 = $ format3
";
?>
< / BODY >
< / HTML >

Now this Calculus functions in PHP programming , Good luck and study.

0 komentar:

Post a Comment