Matemáticas#
Introducción#
Math incluye funciones integradas de Python y el módulo completo math
, disponible automáticamente en VEXcode AIM. Estas herramientas permiten realizar todo tipo de operaciones, desde aritmética básica hasta trigonometría avanzada, redondeo y logaritmos.
Usa estas funciones y constantes para calcular posiciones, ángulos, distancias y otros valores numéricos para tu robot. También puedes convertir entre grados y radianes, evaluar expresiones y trabajar con valores especiales como infinito y NaN.
A continuación se muestra una lista de funciones matemáticas, constantes y utilidades disponibles:
Funciones integradas: herramientas matemáticas comunes incluidas con Python.
abs – Returns the absolute value of a number.
round – Rounds a number to a specified number of decimal places.
min – Returns the smallest of the input values.
max – Returns the largest of the input values.
sum – Adds up all values in an iterable.
divmod – Returns the quotient and remainder as a tuple.
pow – Raises a number to a power, optionally with a modulus.
int – Converts a value to an integer.
float – Converts a value to a floating-point number.
Constantes – Valores predefinidos del módulo math
.
math.pi – The constant π (pi).
math.tau – The constant tau (2π).
math.e – Euler’s number, base of the natural log.
math.inf – Positive infinity.
math.nan – Not a Number (NaN).
Trigonometría – Calcular ángulos y relaciones entre lados.
math.sin – Sine of an angle in radians.
math.cos – Cosine of an angle in radians.
math.tan – Tangent of an angle in radians.
math.atan – Arctangent of a value in radians.
math.atan2 – Arctangent of y/x in radians, considering the quadrant.
math.asin – Arcsine of a value in radians.
math.acos – Arccosine of a value in radians.
math.degrees – Converts radians to degrees.
math.radians – Converts degrees to radians.
Hiperbólicas: funciones trigonométricas avanzadas.
math.sinh – Hyperbolic sine of a value.
math.cosh – Hyperbolic cosine of a value.
math.tanh – Hyperbolic tangent of a value.
math.asinh – Inverse hyperbolic sine.
math.acosh – Inverse hyperbolic cosine.
math.atanh – Inverse hyperbolic tangent.
Redondeo y valor absoluto: ajuste la precisión o la dirección.
math.ceil – Rounds up to the nearest integer.
math.floor – Rounds down to the nearest integer.
math.trunc – Removes the decimal portion.
math.fabs – Returns the absolute value as a float.
Exponentes y logaritmos: cálculos de potencia, raíz y logaritmo.
math.pow – Raises a number to a power.
math.sqrt – Returns the square root.
math.exp – Calculates e to the power of x.
math.log – Natural logarithm (base e).
math.log10 – Base-10 logarithm.
math.log2 – Base-2 logarithm.
math.factorial – Factorial of an integer.
math.expm1 – More accurate result for
e^x - 1
.
Operaciones de punto flotante: inspeccionar o descomponer valores flotantes.
math.modf – Returns the fractional and integer parts of a float.
math.frexp – Decomposes a number into mantissa and exponent.
math.fmod – Remainder with sign of the dividend.
math.copysign – Returns a value with the sign of another.
math.ldexp – Computes
x * (2 ** exp)
.
Comparación y aproximación: verifique valores con tolerancias o categorías.
math.isclose – Tests if two values are approximately equal.
math.isfinite – Checks if a number is finite.
math.isinf – Checks if a number is infinite.
math.isnan – Checks if a value is NaN.
Error y Gamma – Funciones matemáticas especiales.
math.gamma – Gamma function (generalized factorial).
math.lgamma – Logarithmic gamma.
math.erf – Error function.
math.erfc – Complementary error function.
Funciones integradas#
Python proporciona varias funciones integradas que le permiten realizar operaciones matemáticas dentro de su proyecto.
abs#
abs
devuelve el valor absoluto de un número, eliminando cualquier signo negativo.
Uso:
abs(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante. |
# Get the absolute value of -10
abs_result = abs(-10)
robot.screen.print(abs_result)
# abs_result = 10
round#
round
redondea un número a una cantidad específica de decimales.
Uso:
round(x, ndigits)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante. |
|
Opcional. El número de decimales a redondear. El valor predeterminado es 0. |
# Round 5.7 to the nearest integer
round_int_result = round(5.7)
robot.screen.print(round_int_result)
# round_int_result = 6
# Round 3.14159 to 2 decimal places
round_result = round(3.14159, 2)
robot.screen.print(round_result)
# round_result = 3.14
min#
min
devuelve el valor más pequeño de múltiples argumentos o un iterable.
Uso:
min(arg1, arg2, ...)
o min(sequence)
Parámetro |
Descripción |
---|---|
|
Los números para comparar. |
|
Una lista, tupla u otra secuencia que contiene números. |
# Get the smallest number from 3, 7, and 1
min_result = min(3, 7, 1)
robot.screen.print(min_result)
# min_result = 1
# Get the smallest value from a list
min_list_result = min([10, 4, 25, 1])
robot.screen.print(min_list_result)
# min_list_result = 1
max#
max
devuelve el valor más grande de múltiples argumentos o un iterable.
Uso:
max(arg1, arg2, ...)
o max(sequence)
Parámetro |
Descripción |
---|---|
|
Los números para comparar. |
|
Una lista, tupla u otra secuencia que contiene números. |
# Get the largest number from 3, 7, and 1
max_result = max(3, 7, 1)
robot.screen.print(max_result)
# max_result = 7
# Get the largest value from a list
max_list_result = max([10, 4, 25, 1])
robot.screen.print(max_list_result)
# max_list_result = 25
sum#
sum
suma todos los valores de un iterable, con un valor inicial opcional.
Uso:
sum(sequence, start)
Parámetro |
Descripción |
---|---|
|
Una lista, tupla u otra secuencia que contiene números. |
|
Opcional. Un valor para añadir a la suma. El valor predeterminado es 0. |
# Calculate the sum of a list of numbers
sum_result = sum([1, 2, 3, 4, 5])
robot.screen.print(sum_result)
# sum_result = 15
# Calculate the sum of a list with a starting value of 10
sum_with_start = sum([1, 2, 3], 10)
robot.screen.print(sum_with_start)
# sum_with_start = 16
divmod#
divmod
devuelve una tupla que contiene el cociente y el resto de una operación de división.
Uso:
divmod(a, b)
Parámetro |
Descripción |
---|---|
|
El dividendo. |
|
El divisor. |
# Perform integer division and remainder of 10 / 3
divmod_result = divmod(10, 3)
robot.screen.print(divmod_result)
# divmod_result = (3, 1)
pow#
pow
eleva un número a una potencia y opcionalmente realiza una operación de módulo.
Uso:
pow(x, y, mod)
Parámetro |
Descripción |
---|---|
|
El número base. |
|
El exponente. |
|
Opcional. Un valor de módulo. Si se proporciona, devuelve |
# Calculate 2 raised to the power of 3
pow_result = pow(2, 3)
robot.screen.print(pow_result)
# pow_result = 8
# Calculate (5 ** 3) % 7
pow_mod_result = pow(5, 3, 7)
robot.screen.print(pow_mod_result)
# pow_mod_result = 6
int#
int
convierte un número o una cadena en un entero. También admite la conversión de base al convertir desde una cadena.
Uso:
int(x, base)
Parámetro |
Descripción |
---|---|
|
Un número, cadena u otro objeto para convertir. |
|
Opcional. La base numérica que se usará para la conversión. El valor predeterminado es 10. |
# Convert a float to an integer to get rid of decimals
price = 19.99
price_int = int(price)
robot.screen.print(f"{price_int} coins")
# Output: 19 coins
# Convert a string into an integer to use in calculations
user_input = "55"
user_number = int(user_input)
robot.screen.print(user_number * 2)
# Output: 110
float#
float
convierte un número o cadena en un número de punto flotante.
Uso:
float(x)
Parámetro |
Descripción |
---|---|
|
Un número, cadena u otro objeto para convertir. |
# Convert division result to a float
num_apples = 6
num_people = 2
apples_per_person = float(num_apples) / num_people
robot.screen.print(apples_per_person)
# Output: 3.00
# Convert a string into a float to use in calculations
user_input = "23.4"
user_number = float(user_input)
robot.screen.print(user_number * 3)
# Output: 70.20
Módulo de Matemáticas#
El módulo math
de MicroPython proporciona métodos adicionales para realizar cálculos matemáticos comunes. Estos métodos incluyen operaciones trigonométricas, logarítmicas y otras operaciones numéricas.
El módulo math
se importa de forma predeterminada en VEXcode.
Constants#
Las constantes son valores predefinidos que permanecen fijos durante un proyecto. Pueden utilizarse en cálculos sin necesidad de definirlas ni asignarlas.
pi#
pi
da la constante matemática π, la relación entre la circunferencia de un círculo y su diámetro.
Uso:
math.pi
# Calculate the area of a circle with radius 5 using pi
circle_area = math.pi * 5 * 5
robot.screen.print(circle_area)
# circle_area = 78.54
tau#
tau
da el valor de 2π.
Uso:
math.tau
# Calculate the circumference of a circle with radius
circumference = math.tau * 5
robot.screen.print(circumference)
# circumference = 31.42
mi#
e
da la base del logaritmo natural.
Uso:
math.e
# Calculate e raised to the power of 2
e_power = math.pow(math.e, 2)
robot.screen.print(e_power)
# e_power = 7.39
información#
inf
devuelve el infinito positivo como un flotante.
Uso:
math.inf
# Check if infinity is infinite
inf_value = math.inf
if math.isinf(inf_value):
robot.screen.print("Infinity")
# Prints "Infinity"
yaya#
nan
representa un flotante especial para “No es un número” (NaN).
Uso:
math.nan
# Check if nan is Not a Number
nan_value = math.nan
if math.isnan(nan_value):
robot.screen.print("Not a Number")
# Prints "Not a Number"
Trigonometry#
pecado#
sin
calcula el seno de un ángulo en radianes y devuelve un valor flotante.
Uso:
math.sin(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa un ángulo en radianes. |
# Calculate the sine of 30 degrees in radians
sine_result = math.sin(math.radians(30))
robot.screen.print(sine_result)
# sine_result = 0.50
porque#
cos
calcula el coseno de un ángulo en radianes y devuelve un valor flotante.
Uso:
math.cos(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa un ángulo en radianes. |
# Calculate the cosine of 60 degrees in radians
cosine_result = math.cos(math.radians(60))
robot.screen.print(cosine_result)
# cosine_result = 0.50
broncearse#
tan
calcula la tangente de un ángulo en radianes y devuelve un valor flotante.
Uso:
math.tan(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa un ángulo en radianes. |
# Calculate the tangent of 45 degrees in radians
tangent_result = math.tan(math.radians(45))
robot.screen.print(tangent_result)
# tangent_result = 1.00
Atán#
atan
calcula la tangente inversa (arco tangente) de un número y devuelve un punto flotante que representa el ángulo en radianes.
Uso:
math.atan(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero. |
# Calculate the arc tangent of 1 in degrees
arc_tangent_result = math.degrees(math.atan(1.0))
robot.screen.print(arc_tangent_result)
# arc_tangent_result = 45.00
atan2#
atan2
calcula el valor principal de la tangente inversa de y/x y devuelve un flotante que representa el ángulo en radianes.
Uso:
math.atan2(y, x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero que representa la coordenada y. |
|
Un número flotante o entero que representa la coordenada x. |
# Calculate the inverse tangent of 1/1 in degrees
atan2_result = math.degrees(math.atan2(1.0, 1.0))
robot.screen.print(atan2_result)
# atan2_result = 45.00
asiático#
asin
calcula el seno inverso (arcoseno) de un número y devuelve un punto flotante que representa el ángulo en radianes.
Uso:
math.asin(x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero entre -1 y 1. |
# Calculate the arc sine of 0.5 in degrees
arc_sine_result = math.degrees(math.asin(0.5))
robot.screen.print(arc_sine_result)
# arc_sine_result = 30.00
acos#
acos
calcula el coseno inverso (arcocoseno) de un número y devuelve un flotante que representa el ángulo en radianes.
Uso:
math.acos(x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero entre -1 y 1. |
# Calculate the arc cosine of 0.5 in degrees
arc_cosine_result = math.degrees(math.acos(0.5))
robot.screen.print(arc_cosine_result)
# arc_cosine_result = 60.00
grados#
degrees
convierte un ángulo de radianes a grados.
Uso:
math.degrees(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa un ángulo en radianes. |
# Convert pi radians to degrees
degrees_result = math.degrees(math.pi)
robot.screen.print(degrees_result)
# degrees_result = 180.00
radianes#
radians
convierte un ángulo de grados a radianes.
Uso:
math.radians(x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero que representa un ángulo en grados. |
# Convert 180 degrees to radians
radians_result = math.radians(180)
robot.screen.print(radians_result)
# radians_result = 3.14
Hyperbolics#
Sinh#
sinh
calcula el seno hiperbólico de x
.
Uso:
math.sinh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the hyperbolic sine of 1
sinh_result = math.sinh(1)
robot.screen.print(sinh_result)
# sinh_result = 1.18
aporrear#
cosh
calcula el coseno hiperbólico de x
.
Uso:
math.cosh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the hyperbolic cosine of 1
cosh_result = math.cosh(1)
robot.screen.print(cosh_result)
# cosh_result = 1.54
tanh#
tanh
calcula la tangente hiperbólica de x
.
Uso:
math.tanh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the hyperbolic tangent of 1
tanh_result = math.tanh(1)
robot.screen.print(tanh_result)
# tanh_result = 0.76
asiático#
asinh
calcula el seno hiperbólico inverso de x
.
Uso:
math.asinh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the inverse hyperbolic sine of 1
asinh_result = math.asinh(1)
robot.screen.print(asinh_result)
# asinh_result = 0.88
acosh#
acosh
calcula el coseno hiperbólico inverso de x
.
Uso:
math.acosh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero mayor o igual a 1. |
# Calculate the inverse hyperbolic cosine of 2
acosh_result = math.acosh(2)
robot.screen.print(acosh_result)
# acosh_result = 1.32
Atanh#
atanh
calcula la tangente hiperbólica inversa de x
.
Uso:
math.atanh(x)
Parámetro |
Descripción |
---|---|
|
Un flotante entre -1 y 1 (exclusivo). |
# Calculate the inverse hyperbolic tangent of 0.5
atanh_result = math.atanh(0.5)
robot.screen.print(atanh_result)
# atanh_result = 0.55
Rounding & Absolute Values#
fortificar techo#
ceil
redondea un número al entero más cercano.
Uso:
math.ceil(x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero que se redondeará hacia arriba. |
# Round 3.7 up to the nearest integer
ceil_result = math.ceil(3.7)
robot.screen.print(ceil_result)
# ceil_result = 4
piso#
floor
redondea un número hacia abajo hasta el entero más cercano.
Uso:
math.floor(x)
Parámetro |
Descripción |
---|---|
|
Un número flotante o entero que se redondeará hacia abajo. |
# Round 3.7 down to the nearest integer
floor_result = math.floor(3.7)
robot.screen.print(floor_result)
# floor_result = 3
tronco#
trunc
elimina la parte decimal de un número sin redondearlo.
Uso:
math.trunc(x)
Parámetro |
Descripción |
---|---|
|
Un flotador que debe truncarse. |
# Remove the decimal part of 3.7
trunc_result = math.trunc(3.7)
robot.screen.print(trunc_result)
# trunc_result = 3
fábricas#
fabs
devuelve el valor absoluto de un número como un flotante.
Uso:
math.fabs(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero. |
# Get the absolute value of -3.7
fabs_result = math.fabs(-3.7)
robot.screen.print(fabs_result)
# fabs_result = 3.70
Exponents & Logarithms#
poder#
pow
eleva x a la potencia de y y devuelve un valor flotante, incluso si ambas entradas son números enteros.
Uso:
math.pow(x, y)
Parámetro |
Descripción |
---|---|
|
Una base de número flotante o entero. |
|
Un exponente flotante o entero. |
# Calculate 2 raised to the power of 3
power_result = math.pow(2, 3)
robot.screen.print(power_result)
# power_result = 8.00
raíz cuadrada#
sqrt
calcula la raíz cuadrada de un número y devuelve un valor flotante, incluso para cuadrados perfectos.
Uso:
math.sqrt(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante no negativo. |
# Calculate the square root of 16
sqrt_result = math.sqrt(16)
robot.screen.print(sqrt_result)
# sqrt_result = 4.00
exp#
exp
calcula el exponencial de un número y devuelve un flotante.
Uso:
math.exp(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero. |
# Calculate e raised to the power of 1
exp_result = math.exp(1)
robot.screen.print(exp_result)
# exp_result = 2.72
registro#
log
calcula el logaritmo natural de un número y devuelve un valor flotante.
Uso:
math.log(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante positivo. |
# Calculate the natural logarithm (base e) of 7.389056
log_result = math.log(7.389056)
robot.screen.print(log_result)
# log_result = 2.00
registro10#
log10
calcula el logaritmo en base 10 de un número y devuelve un valor flotante.
Uso:
math.log10(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante positivo. |
# Calculate the base-10 logarithm of 1000
log10_result = math.log10(1000)
robot.screen.print(log10_result)
# log10_result = 3.00
registro2#
log2
calcula el logaritmo en base 2 de un número y devuelve un valor flotante, incluso cuando x
es una potencia de 2.
Uso:
math.log2(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante positivo. |
# Calculate the base-2 logarithm of 8
log2_result = math.log2(8)
robot.screen.print(log2_result)
# log2_result = 3.00
factorial#
factorial
devuelve el factorial de un entero x
, que es el producto de todos los enteros positivos hasta x
.
Uso:
math.factorial(x)
Parámetro |
Descripción |
---|---|
|
Un número entero no negativo. |
# Calculate 5 factorial (5!)
factorial_result = math.factorial(5)
robot.screen.print(factorial_result)
# factorial_result = 120
expm1#
expm1
calcula e<sup>x</sup> - 1
, que es más preciso para x
pequeño.
Uso:
math.expm1(x)
Parámetro |
Descripción |
---|---|
|
El valor del exponente. |
# Compute expm1(1) (e^1 - 1)
expm1_result = math.expm1(1)
robot.screen.print(expm1_result)
# expm1_result = 1.72
Floating Point Operations#
modf#
modf
descompone un número en sus partes fraccionaria y entera y devuelve una tupla (fractional part, integer part)
, ambas como flotantes.
Uso:
math.modf(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero para descomponer. |
# Decompose 3.14159 into fractional and integer parts
fractional_part, integer_part = math.modf(3.14159)
robot.screen.print(fractional_part)
robot.screen.next_row()
robot.screen.print(integer_part)
# fractional_part = 0.14
# integer_part = 3.00
frexp#
frexp
descompone un número en su mantisa y exponente y devuelve una tupla (mantissa, exponent)
, donde la mantisa es un flotante y el exponente es un entero.
Uso:
math.frexp(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero para descomponer. |
# Decompose 16 into its mantissa and exponent
mantissa, exponent = math.frexp(16)
robot.screen.print(mantissa)
robot.screen.next_row()
robot.screen.print(exponent)
# mantissa = 0.50
# exponent = 5
modo de funcionamiento#
fmod
devuelve el resto de la división conservando el signo del dividendo (x
).
Uso:
math.fmod(x, y)
Parámetro |
Descripción |
---|---|
|
El dividendo. |
|
El divisor. |
# Calculate remainder of 10 / 3
# that preserves the sign of 10
fmod_result = math.fmod(10, 3)
robot.screen.print(fmod_result)
# fmod_result = 1.00
firma de derechos de autor#
copysign
devuelve x con el signo y
.
Uso:
math.copysign(x, y)
Parámetro |
Descripción |
---|---|
|
El valor a modificar. |
|
El valor cuyo signo se copiará. |
# Return -10 with the sign of 3 (positive)
copysign_result = math.copysign(-10, 3)
robot.screen.print(copysign_result)
# copysign_result = 10.00
ldexp#
ldexp
calcula x * (2 ** exp)
, que es equivalente a x * 2<sup>exp</sup>
.
Uso:
math.ldexp(x, exp)
Parámetro |
Descripción |
---|---|
|
El valor base. |
|
El exponente. |
# Compute 3 * (2 ** 4)
ldexp_result = math.ldexp(3, 4)
robot.screen.print(ldexp_result)
# ldexp_result = 48.00
Comparison & Approximation#
está cerca#
isclose
comprueba si dos números son aproximadamente iguales dentro de una tolerancia.
Uso:
math.isclose(a, b, rel_tol, abs_tol)
Parámetro |
Descripción |
---|---|
|
El primer número a comparar. |
|
El segundo número a comparar. |
|
Opcional. La diferencia máxima permitida entre a y b, en relación con su tamaño. El valor predeterminado es 1e-09 (muy pequeño). |
|
Opcional. Un margen de error fijo, útil al comparar números cercanos a cero. El valor predeterminado es 0.0. |
Nota: Si se proporcionan rel_tol
y abs_tol
, la condición que se cumpla primero determina el resultado.
# Check if 1.000000001 and 1.0 are close
# within the default tolerance
isclose_result = math.isclose(1.000000001, 1.0)
robot.screen.print(isclose_result)
# isclose_result = True
# Check if 0.0000001 and 0.0 are close
# using absolute tolerance
isclose_result = math.isclose(0.0000001, 0.0, abs_tol=1e-07)
robot.screen.print(isclose_result)
# isclose_result = True
# Check if 1000000.0 and 1000000.1 are close
# with a stricter tolerance
isclose_result = math.isclose(1000000.0, 1000000.1, rel_tol=1e-10)
robot.screen.print(isclose_result)
# isclose_result = False
es finito#
isfinite
comprueba si un número es finito. Este método devuelve un valor booleano:
True
- El número es finito.False
- El número es infinito.
Uso:
math.isfinite(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero para comprobar. |
# Check if 42 is a finite number (returns True)
is_finite_true = math.isfinite(42)
robot.screen.print(is_finite_true)
# is_finite_true = True
# Check if infinity is a finite number (returns False)
is_finite_false = math.isfinite(math.inf)
robot.screen.print(is_finite_false)
# is_finite_false = False
es inf#
isinf
comprueba si un número es infinito. Este método devuelve un valor booleano:
True
- El número es infinito.False
- El número es finito.
Uso:
math.isinf(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero para comprobar. |
# Check if infinity is an infinite number (returns True)
is_inf_true = math.isinf(math.inf)
robot.screen.print(is_inf_true)
# is_inf_true = True
# Check if 42 is an infinite number (returns False)
is_inf_false = math.isinf(42)
robot.screen.print(is_inf_false)
# is_inf_false = False
Isnan#
isnan
comprueba si un número es NaN (No es un número). Este método devuelve un valor booleano:
True
- El número es NaN.False
- El número es un número válido.
Uso:
math.isnan(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero para comprobar. |
# Check if NaN (Not a Number) is NaN (returns True)
is_nan_true = math.isnan(math.nan)
robot.screen.print(is_nan_true)
# is_nan_true = True
# Check if 42 is NaN (returns False)
is_nan_false = math.isnan(42)
robot.screen.print(is_nan_false)
# is_nan_false = False
Error and Gamma Calculations#
gama#
gamma
calcula la función gamma de x
, que generaliza la función factorial para números reales y complejos. Para un entero n
, gamma(n) = (n-1)!
.
Uso:
math.gamma(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante positivo. |
# Calculate the gamma function of 5 (equivalent to 4!)
gamma_result = math.gamma(5)
robot.screen.print(gamma_result)
# gamma_result = 24.00
lgamma#
lgamma
calcula el logaritmo natural de la función gamma
.
Uso:
math.lgamma(x)
Parámetro |
Descripción |
---|---|
|
Un número entero o flotante positivo. |
# Calculate the natural logarithm of the
# gamma function of 5
lgamma_result = math.lgamma(5)
robot.screen.print(lgamma_result)
# lgamma_result = 3.18
erf#
erf
calcula la función de error de x
.
Uso:
math.erf(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the error function of 1
erf_result = math.erf(1)
robot.screen.print(erf_result)
# erf_result = 0.84
erfc#
erfc
calcula la función de error complementaria de x
, que se define como 1 - erf(x)
.
Uso:
math.erfc(x)
Parámetro |
Descripción |
---|---|
|
Un flotante o entero que representa el valor de entrada. |
# Calculate the complementary error function of 1
erfc_result = math.erfc(1)
robot.screen.print(erfc_result)
# erfc_result = 0.16