PHP MATHEMATICS [MATH] FUNCTIONS - 2

in #utopian-io7 years ago (edited)

What Will I Learn?

  • PHP Math Functions

Requirements

  • PHP
  • Linux

Difficulty

  • Basic

Trigonometry

PHP, has provided ready-made functions to perform trigonometric calculations and the following table shows which functions these functions perform.

FunctionExplanation
sin()It generates the sine value of the input radian expression.
cos()It generates the cosine value of the entered radian expression.
tan()It generates the tangent value of the input radian expression.
asin()It produces the inverse sinusoidal value of the input expression.
acos()Produces the inverse cosine value of the input expression.
atan()Generates the inverse tangent value of the input expression.
<?php
$value = 90;
echo sin ($value) . '<br>';                                               #Result: 0.893996663601
echo sin (deg2rad($value) ) . '<br>';                        #Result: 1
echo sin (pi()/2) . '<br>';                                                  #Result: 1
?>

Above is an example of the sin() function. Similarly, the cos() and tan() functions are used in this way. When we examine the object, we can see that 0.89 float value is returned when 90 (integer) is sent to sin() function.

<?php
$value = 1;
$radians = asin ($value);
echo $radians. '<br>' ;                                        #Result: 1.57079632679
echo rad2deg($radyan) . '<br>' ;                  #Result: 90
?>

In the above example, I gave an example through the asin() function. You can also use the acos() and assign() functions in the same way. In the example you want to do a reverse sine calculation for y=1. Therefore, when the value of the inverse sinus is calculated, the result will be in terms of radians. We can get the results by printing the calculated radian result and the converted degree of the radian on the screen.

Random Number Poducers

For example;
Random number generators are used in password generators or in part of the algorithm in applications that perform different operations according to the value of a randomly generated number. In this section, we will examine the random number functions that you can use with PHP. The following table contains the functions and explanations required to create a random number.

FunctionExplanation
rand()Produces a random number.
getrandmax()It shows the largest possible value that can be generated with the rand() function.
mt_rand()It generates random numbers in faster time.
mt_getrandmax()It shows the largest possible value that can be generated with the mt_getrandmax() function.
<?php
echo 'rand: ' . getrandmax () . ' <br>' ;                             #Result: 32767
echo rand () . '<br>'; 
echo rand (0,10) . '<br> <br>';
echo 'mt_rand: ' .mt_getrandmax() . '<br>';                 #Result: 2147483647
echo mt_rand () . '<br>' ;
echo mt_rand (20, 30) ;
?>

When you run the above example, different numbers will be generated each time. Only the values of getrandmax() and mt_getrandmax() will be fixed. These two functions were used for informational purposes. If you use rand() without any parameters, it returns a random number between 0 and getrandmax(). If min and max are specified, a random number is generated between these two values. For example; In the case of mt_rand (20,30) it means that a random number will be generated from the numbers 20 to 30 using the mt_rand() function.

Other Functions

There are a few more functions I could not fit into the above headers. We will come to the end of functions that perform mathematical calculations by specifying these functions.

FunctionExplanation
max()Returns the largest of the numbers sent as a parameter.
min()Returns the smallest of the numbers sent as a parameter.
pi()Returns the absolute PI number, deg2rad (180).
<?php
echo max (2,80,1.5, -20, 70) . '<br>' ;
echo min (2,80,1.5, -20, 70). '<br>';
# Various ways of obtaining PI
echo pi () . '<br>' ;
echo deg2rad(180) . '<br>' ;
echo M_Pİ . '<br>' ;
?>

Our mathematical functions are finished here. Thank you for taking the time and reading it.

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Hi, this is the reason your contribution was rejected

  • Tutorials must be technical instructions that teach non-trivial aspects of an open-source project.

All the information in your tutorial can already be found in PHP's documentation, e.g. for the sin() function or the getrandmax(); it doesn't provide any unique value. For tutorial tutorials I recommend you don't create a tutorial where you simply explain what certain functions do (especially when it's already explained in the official documentation), as that isn't considered a valid contribution to Utopian.io and thus won't be accepted.

You can contact us on Discord.
[utopian-moderator]

I do not know if you have ever written PHP, but in most software languages the code is already written with functions. What is important here is the way the function is used and given examples. The written values of the functions are not constant and the code structure is determined according to the variable being written. I believe that this tutorial content conforms to the rules and standards. Please do a detailed review or check with your supervisors. Thank you for your understanding.

As I said, a tutorial where you simply explain what certain functions do (especially trivial ones like these) and show basic examples cannot be considered a valid contribution to Utopian.io. It is simply too trivial and has little to no value. I feel like I already gave a detailed review in the comment above, so if you disagree with my decision, then feel free to contact my supervisor.

Coin Marketplace

STEEM 0.20
TRX 0.25
JST 0.039
BTC 97542.75
ETH 3458.83
USDT 1.00
SBD 3.15