Funzioni matematiche

  1. abs(x), valore assoluto
  2. pi, 3.14159….
  3. sin(x)
  4. cos(x)
  5. tan(x)
  6. asin(x), arcoseno
  7. acos(x), arcocoseno
  8. atan(x), arcotangente
  9. atan2(y,x), angolo la cui tangente รจ y/x
  10. exp(x), e elevato alla x
  11. log(x), logaritmo naturale, in base e
    • con log(x)/log(10), si ottiene il logaritmo in base 10
  12. pow(x,y), x elevato alla y
  13. sqrt(x), radice quadrata
  14. ceil(x), round up to nearest integer
  15. floor(x), round down to nearest integer
  16. round(x), round to nearest integer
  17. max(x,y,z, …), the largest of x,y,z
  18. min(x,y,z, …), the smallest of x,y,z
  19. random(), pseudorandom number 0 to 1
  20. factorial(x), x! = x*(x-1)*(x-2)….(1)
  21. combin(x,y), x!/(y!*(x-y)!)
  22. degrees(x), conversione in gradi, di radianti
  23. radians(x), conversione in radianti, di gradi

print(factorial(4)) # gives 24
print(combin(10,2)) # gives 45

The factorial function factorial(N) is N!; 4! is (4)(3)(2)(1) = 24, and 0! is defined to be 1.
The combin function is combin(a,b) = a!/(b!*(a-b)!)
.

A major use of these functions is in calculating the number of ways of arranging a group of objects. For example, if there are 5 numbered balls in a sack, there are factorial(5) = 5! = 5*4*3*2*1 = 120 ways of taking them sequentially out of the sack (5 possibilities for the first ball, 4 for the next, and so on).

If on the other hand the 5 balls are not numbered, but 2 are green and 3 are red, of the 120 ways of picking the balls there are 2! indistinguishable ways of arranging the green balls and 3! ways of arranging the red balls, so the number of different arrangements of the balls is combin(5,2) = 5!/(3!*2!) = 10.

Logically, the combin function is just a combination of factorial functions. However, cancellations in the numerator and denominator make it possible to evaluate the combin function for values of its arguments that would overflow the factorial function, due to the limited size of floating-point numbers. For example, combin(5,2) = 5!/(3!*2!) = (5*4)/(2*1) = (2.5*4) = 10, and we didn’t have to evaluate any of the factorials fully.

 

Notice: This work is licensed under a BY-NC-SA. Permalink: Funzioni matematiche

Comments are closed.