الرياضيات#

مقدمة#

Math includes both built-in Python functions and the full math module, which is automatically available in VEXcode GO. These tools allow you to perform everything from basic arithmetic to advanced trigonometry, rounding, and logarithmic operations.

استخدم هذه الدوال والثوابت لحساب المواضع والزوايا والمسافات وغيرها من القيم العددية لروبوتك. يمكنك أيضًا التحويل بين الدرجات والراديان، وتقييم التعبيرات، والتعامل مع قيم خاصة مثل اللانهاية وNaN.

فيما يلي قائمة بالوظائف الرياضية والثوابت والأدوات المساعدة المتاحة:

الوظائف المدمجة – أدوات الرياضيات الشائعة المضمنة في بايثون.

  • abs – تُرجع القيمة المطلقة للعدد.

  • round – يقوم بتقريب رقم إلى عدد محدد من المنازل العشرية.

  • min – تُرجع أصغر قيمة من قيم الإدخال.

  • max – تُرجع أكبر قيمة من قيم الإدخال.

  • sum – يجمع كل القيم في مجموعة قابلة للتكرار.

  • divmod – تُرجع ناتج القسمة والباقي كزوج مرتب.

  • pow – يرفع عددًا إلى قوة، مع إمكانية إضافة باقي القسمة.

  • int – يحول قيمة إلى عدد صحيح.

  • float – يحول قيمة إلى عدد عشري.

Constants – Predefined values from the math module.

  • math.pi – الثابت π (pi).

  • math.tau – الثابت تاو (2π).

  • math.e – عدد أويلر، أساس اللوغاريتم الطبيعي.

علم المثلثات – حساب الزوايا والعلاقات بين الأضلاع.

  • math.sin – جيب الزاوية بالراديان.

  • math.cos – جيب تمام الزاوية بالراديان.

  • math.tan – ظل الزاوية بالراديان.

  • math.atan – دالة الظل العكسي لقيمة بالراديان.

  • math.atan2 – ظل الزاوية العكسي لـ y/x بالراديان، مع الأخذ في الاعتبار الربع.

  • math.asin – Arcsine of a value in radians.

  • math.acos – معكوس جيب التمام لقيمة بالراديان.

  • math.degrees – يحول الراديان إلى درجات.

  • math.radians – يحول الدرجات إلى راديان.

التقريب والقيمة المطلقة - ضبط الدقة أو الاتجاه.

  • math.ceil – التقريب إلى أقرب عدد صحيح.

  • math.floor – التقريب إلى أقرب عدد صحيح.

  • math.trunc – يزيل الجزء العشري.

  • math.fabs – تُرجع القيمة المطلقة كعدد عشري.

الأسس واللوغاريتمات – حسابات القوة والجذر واللوغاريتم.

  • math.pow – يرفع عددًا إلى قوة.

  • math.sqrt – تُرجع الجذر التربيعي.

  • math.exp – يحسب e مرفوعًا للأس x.

  • math.log – احسب لوغاريتم x.

  • math.log10 – يحسب اللوغاريتم العشري لـ x.

عمليات الفاصلة العائمة – فحص أو تحليل قيم الفاصلة العائمة.

  • math.modf – تُرجع الأجزاء الكسرية والصحيحة من عدد عشري.

  • math.frexp – يحلل العدد إلى جزء من الكسر والأس.

  • math.fmod – الباقي مع إشارة المقسوم.

  • math.copysign – تُرجع قيمة بإشارة قيمة أخرى.

  • math.ldexp – يحسب x * (2 ** exp).

الوظائف المدمجة#

توفر لغة بايثون العديد من الدوال المدمجة التي تسمح لك بإجراء العمليات الحسابية داخل مشروعك.

abs#

تقوم الدالة abs بإرجاع القيمة المطلقة للعدد، مع إزالة أي إشارة سالبة.

Usage:
abs(x)

المعلمة

وصف

x

عدد صحيح أو عدد عشري.

def main():
    # Get the absolute value of -10
    abs_result = abs(-10)
    console.print(abs_result)

# abs_result = 10

# Start threads — Do not delete
start_thread(main)

round#

round تقوم بتقريب رقم إلى عدد محدد من المنازل العشرية.

Usage:
round(x, ndigits)

المعلمة

وصف

x

عدد صحيح أو عدد عشري.

ndigits

اختياري. عدد المنازل العشرية المراد التقريب إليها. القيمة الافتراضية هي 0.

def main():
    # Round 5.7 to the nearest integer
    round_int_result = round(5.7)
    console.print(round_int_result)

# round_int_result = 6

# Start threads — Do not delete
start_thread(main)

def main():
    # Round 3.14159 to 2 decimal places
    round_result = round(3.14159, 2)
    console.print(round_result, precision=2)

# round_result = 3.14

# Start threads — Do not delete
start_thread(main)

min#

تقوم الدالة min بإرجاع أصغر قيمة من بين عدة وسائط أو من كائن قابل للتكرار.

Usage:
min(arg1, arg2, …) or min(sequence)

المعلمة

وصف

arg1, arg2, …

الأرقام للمقارنة.

sequence

قائمة أو صف أو تسلسل آخر يحتوي على أرقام.

def main():
    # Get the smallest number from 3, 7, and 1
    min_result = min(3, 7, 1)
    console.print(min_result)

# min_result = 1

# Start threads — Do not delete
start_thread(main)

def main():
    # Get the smallest value from a list
    min_list_result = min([10, 4, 25, 1])
    console.print(min_list_result)

# min_list_result = 1

# Start threads — Do not delete
start_thread(main)

max#

تُعيد الدالة max أكبر قيمة من بين عدة وسائط أو من كائن قابل للتكرار.

Usage:
max(arg1, arg2, …) or max(sequence)

المعلمة

وصف

arg1, arg2, …

الأرقام للمقارنة.

sequence

قائمة أو صف أو تسلسل آخر يحتوي على أرقام.

def main():
    # Get the largest number from 3, 7, and 1
    max_result = max(3, 7, 1)
    console.print(max_result)

# max_result = 7

# Start threads — Do not delete
start_thread(main)

def main():
    # Get the largest value from a list
    max_list_result = max([10, 4, 25, 1])
    console.print(max_list_result)

# max_list_result = 25

# Start threads — Do not delete
start_thread(main)

sum#

sum يجمع كل القيم في مجموعة قابلة للتكرار، مع قيمة بداية اختيارية.

Usage:
sum(sequence, start)

المعلمة

وصف

sequence

قائمة أو صف أو تسلسل آخر يحتوي على أرقام.

start

اختياري. قيمة تُضاف إلى المجموع. القيمة الافتراضية هي 0.

def main():
    # Calculate the sum of a list of numbers
    sum_result = sum([1, 2, 3, 4, 5])
    console.print(sum_result)

# sum_result = 15

# Start threads — Do not delete
start_thread(main)

def main():
    # Calculate the sum of a list with a starting value of 10
    sum_with_start = sum([1, 2, 3], 10)
    console.print(sum_with_start)

# sum_with_start = 16

# Start threads — Do not delete
start_thread(main)

divmod#

divmod تُرجع مجموعة تحتوي على ناتج القسمة وباقي عملية القسمة.

Usage:
divmod(a, b)

المعلمة

وصف

a

الأرباح الموزعة.

b

المقسوم عليه.

def main():
    # Perform integer division and remainder of 10 / 3
    divmod_result = divmod(10, 3)
    console.print(divmod_result)

# divmod_result = (3, 1)

# Start threads — Do not delete
start_thread(main)

pow#

pow يرفع رقمًا إلى قوة ويقوم اختياريًا بإجراء عملية حسابية على باقي القسمة.

Usage:
pow(x, y, mod)

المعلمة

وصف

x

الرقم الأساسي.

y

الأس.

mod

اختياري. قيمة باقي القسمة. إذا تم توفيرها، فإنها تُرجع (x ** y) % mod.

def main():
    # Calculate 2 raised to the power of 3
    pow_result = pow(2, 3)
    console.print(pow_result)

# pow_result = 8

# Start threads — Do not delete
start_thread(main)

int#

يقوم الأمر int بتحويل رقم أو سلسلة نصية إلى عدد صحيح. كما يدعم تحويل الأساس عند التحويل من سلسلة نصية.

Usage:
int(x, base)

المعلمة

وصف

x

رقم أو سلسلة نصية أو كائن آخر للتحويل.

base

اختياري. أساس العد المستخدم للتحويل. القيمة الافتراضية هي 10.

def main():
    # Convert a float to an integer to get rid of decimals
    price = 19.99
    price_int = int(price)
    console.print("{} coins".format(price_int))

# Output: 19 coins

# Start threads — Do not delete
start_thread(main)

def main():
    # Convert a string into an integer to use in calculations
    user_input = "55"
    user_number = int(user_input)
    console.print(user_number * 2)

# Output: 110

# Start threads — Do not delete
start_thread(main)

float#

float يحول رقمًا أو سلسلة نصية إلى رقم ذي فاصلة عائمة.

Usage:
float(x)

المعلمة

وصف

x

رقم أو سلسلة نصية أو كائن آخر للتحويل.

# 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

وحدة الرياضيات#

توفر وحدة math في لغة MicroPython طرقًا إضافية لإجراء العمليات الحسابية الشائعة. وتشمل هذه الطرق العمليات المثلثية واللوغاريتمية وغيرها من العمليات العددية.

يتم استيراد وحدة math افتراضيًا في VEXcode.

Constants#

الثوابت هي قيم محددة مسبقاً تظل ثابتة طوال فترة المشروع. ويمكن استخدامها في العمليات الحسابية دون الحاجة إلى أي تعريف أو تعيين.

باي#

pi يعطي الثابت الرياضي π، وهو نسبة محيط الدائرة إلى قطرها.

Usage:
math.pi

def main():
    # Calculate the area of a circle with radius 5 using pi
    circle_area = math.pi * 5 * 5
    console.print(circle_area, precision=2)

# circle_area = 78.54

# Start threads — Do not delete
start_thread(main)

تاو#

tau يعطي قيمة 2π.

Usage:
math.tau

def main():
    # Calculate the circumference of a circle with radius
    circumference = math.tau * 5
    console.print(circumference, precision=2)

# circumference = 31.42

# Start threads — Do not delete
start_thread(main)

هـ#

e يعطي أساس اللوغاريتم الطبيعي.

Usage:
math.e

def main():
    # Calculate e raised to the power of 2
    e_power = math.pow(math.e, 2)
    console.print(e_power, precision=2)

# e_power = 7.39

# Start threads — Do not delete
start_thread(main)

Trigonometry#

الخطيئة#

تقوم الدالة sin بحساب جيب الزاوية بالراديان وتعيد قيمة عشرية.

Usage:
math.sin(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يمثل زاوية بالراديان.

def main():
    # Calculate the sine of 
    # 30 degrees in radians
    result = math.sin(math.radians(30))
    console.print(result, precision=2)

# result = 0.50

# Start threads — Do not delete
start_thread(main)

كوس#

تقوم الدالة cos بحساب جيب تمام الزاوية بالراديان وتعيد قيمة عشرية.

Usage:
math.cos(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يمثل زاوية بالراديان.

def main():
    # Calculate the cosine of 
    # 60 degrees in radians
    result = math.cos(math.radians(60))
    console.print(result, precision=2)

# result = 0.50

# Start threads — Do not delete
start_thread(main)

لون برونزي#

تقوم الدالة tan بحساب ظل الزاوية بالراديان وتعيد عددًا صحيحًا.

Usage:
math.tan(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يمثل زاوية بالراديان.

def main():
    # Calculate the tangent of 
    # 45 degrees in radians
    result = math.tan(math.radians(45))
    console.print(result)

# result = 1

# Start threads — Do not delete
start_thread(main)

أسين#

asin يحسب الجيب العكسي (الجيب العكسي) لعدد ما ويعيد عددًا صحيحًا يمثل الزاوية بالراديان.

Usage:
math.asin(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح بين -1 و 1.

def main():
    # Calculate the arc sine 
    # of 0.5 in degrees
    result = math.degrees(math.asin(0.5))
    console.print(result)

# result = 30

# Start threads — Do not delete
start_thread(main)

أكوس#

acos يحسب معكوس جيب التمام (arc cosine) لعدد ما ويعيد عددًا صحيحًا يمثل الزاوية بالراديان.

Usage:
math.acos(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح بين -1 و 1.

def main():
    # Calculate the arc cosine 
    # of 0.5 in degrees
    result = math.degrees(math.acos(0.5))
    console.print(result)

# result = 60

# Start threads — Do not delete
start_thread(main)

أتان#

تقوم atan بحساب الظل العكسي (الظل القوسي) لعدد ما وتعيد عددًا صحيحًا يمثل الزاوية بالراديان.

Usage:
math.atan(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح.

def main():
    # Calculate the arc tangent 
    # of 1 in degrees
    arc_tan = math.atan(1.0)
    result = math.degrees(arc_tan)
    console.print(result)

# result = 45

# Start threads — Do not delete
start_thread(main)

atan2#

atan2 يحسب القيمة الرئيسية لظل الزاوية العكسي لـ y/x ويعيد قيمة عشرية تمثل الزاوية بالراديان.

Usage:
math.atan2(y, x)

المعلمة

وصف

y

عدد عشري أو عدد صحيح يمثل الإحداثي الصادي.

x

عدد عشري أو عدد صحيح يمثل الإحداثي السيني.

def main():
    # Calculate the inverse tangent 
    # of 1/1 in degrees
    atan2 = math.atan2(1.0, 1.0)
    result = math.degrees(atan2)
    console.print(result)

# result = 45

# Start threads — Do not delete
start_thread(main)

الدرجات العلمية#

تقوم الدالة degrees بتحويل الزاوية من الراديان إلى الدرجات وتعيد عددًا صحيحًا.

Usage:
math.degrees(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يمثل زاوية بالراديان.

def main():
    # Convert pi radians to degrees
    degrees_result = math.degrees(math.pi)
    console.print(degrees_result)

# degrees_result = 180

# Start threads — Do not delete
start_thread(main)

الراديان#

radians يحول الزاوية من الدرجات إلى الراديان.

Usage:
math.radians(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يمثل زاوية بالدرجات.

def main():
    # Convert 180 degrees to radians
    radians_result = math.radians(180)
    console.print(radians_result, precision=2)

# radians_result = 3.14

# Start threads — Do not delete
start_thread(main)

Rounding & Absolute Values#

سقف#

ceil تقرب العدد إلى أقرب عدد صحيح.

Usage:
math.ceil(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يتم تقريبه لأعلى.

def main():
    # Round 3.7 up to the nearest integer
    ceil_result = math.ceil(3.7)
    console.print(ceil_result)

# ceil_result = 4

# Start threads — Do not delete
start_thread(main)

أرضية#

الطابق floor.

Usage:
math.floor(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح يتم تقريبه إلى أقرب عدد صحيح أصغر.

def main():
    # Round 3.7 down to the nearest integer
    floor_result = math.floor(3.7)
    console.print(floor_result)

# floor_result = 3

# Start threads — Do not delete
start_thread(main)

trunc#

trunc يزيل الجزء العشري من الرقم دون تقريب.

Usage:
math.trunc(x)

المعلمة

وصف

x

قيمة عشرية سيتم اقتطاعها.

def main():
    # Remove the decimal part of 3.7
    trunc_result = math.trunc(3.7)
    console.print(trunc_result)

# trunc_result = 3

# Start threads — Do not delete
start_thread(main)

فابز#

تقوم الدالة fabs بإرجاع القيمة المطلقة للعدد كعدد عشري.

Usage:
math.fabs(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح.

def main():
    # Get the absolute value of -3.7
    fabs_result = math.fabs(-3.7)
    console.print(fabs_result, precision=1)

# fabs_result = 3.7

# Start threads — Do not delete
start_thread(main)

Exponents & Logarithms#

سجل#

تقوم الدالة log بحساب لوغاريتم عدد ما وإرجاع قيمة عشرية.

Usage:
math.log(x, base)

المعلمة

وصف

x

عدد عشري أو عدد صحيح موجب.

base

اختياري. أساس اللوغاريتم المراد استخدامه. افتراضياً، يكون هذا هو اللوغاريتم الطبيعي.

def main():
    # Calculate the natural logarithm
    # (base e) of 7.389056
    log_result = math.log(7.389056)
    console.print(log_result)

# log_result = 2

# Start threads — Do not delete
start_thread(main)

def main():
    # Calculate the log base 2 of 8
    log_result = math.log(8, 2)
    console.print(log_result)

# log_result = 3

# Start threads — Do not delete
start_thread(main)

log10#

log10 يحسب اللوغاريتم العشري لعدد ما ويعيد قيمة عشرية.

Usage:
math.log10(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح موجب.

def main():
    # Calculate the base-10 logarithm of 100
    log10_result = math.log10(100)
    console.print(log10_result)

# log10_result = 2

# Start threads — Do not delete
start_thread(main)

قوة#

pow يرفع x إلى قوة y ويعيد قيمة عشرية، حتى لو كان كلا المدخلين عددين صحيحين.

Usage:
math.pow(x, y)

المعلمة

وصف

x

أساس عددي عشري أو صحيح.

y

أسّ عشري أو صحيح.

def main():
    # Calculate 2 raised to the power of 3
    power_result = math.pow(2, 3)
    console.print(power_result)

    # power_result = 8

# Start threads — Do not delete
start_thread(main)

الجذر التربيعي#

تقوم الدالة sqrt بحساب الجذر التربيعي لعدد ما وتعيد قيمة عشرية، حتى بالنسبة للأعداد المربعة الكاملة.

Usage:
math.sqrt(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح غير سالب.

def main():
    # Calculate 2 raised to the power of 3
    power_result = math.pow(2, 3)
    console.print(power_result)

# power_result = 8

# Start threads — Do not delete
start_thread(main)

خبرة#

تقوم الدالة exp بحساب الأس لعدد ما وإرجاع قيمة عشرية.

Usage:
math.exp(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح.

def main():
    # Calculate e raised to the power of 1
    exp_result = math.exp(1)
    console.print(exp_result, precision=2)

# exp_result = 2.72

# Start threads — Do not delete
start_thread(main)

Floating Point Operations#

modf#

modf يقوم بتحليل العدد إلى أجزائه الكسرية والصحيحة ويعيد مجموعة (fractional part, integer part)، وكلاهما كأعداد عشرية.

Usage:
math.modf(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح لتحليله.

def main():
    # Decompose 3.14159 into fractional and integer parts
    fractional_part, integer_part = math.modf(3.14159)
    console.print(fractional_part, precision=2)
    console.new_line()
    console.print(integer_part)

# fractional_part = 0.14
# integer_part = 3

# Start threads — Do not delete
start_thread(main)

راديكس#

frexp يقوم بتحليل العدد إلى الجزء العشري والأس الخاص به ويعيد مجموعة (mantissa, exponent)، حيث يكون الجزء العشري عددًا عشريًا والأس عددًا صحيحًا.

Usage:
math.frexp(x)

المعلمة

وصف

x

عدد عشري أو عدد صحيح لتحليله.

def main():
    # Decompose 16 into its mantissa and exponent
    mantissa, exponent = math.frexp(16)
    console.print(mantissa, precision=2)
    console.new_line()
    console.print(exponent)

# mantissa = 0.50
# exponent = 5

# Start threads — Do not delete
start_thread(main)

fmod#

fmod يعيد باقي القسمة مع الحفاظ على إشارة المقسوم (x).

Usage:
math.fmod(x, y)

المعلمة

وصف

x

الأرباح الموزعة.

y

المقسوم عليه.

def main():
    # Calculate remainder of 10 / 3
    # that preserves the sign of 10
    fmod_result = math.fmod(10, 3)
    console.print(fmod_result)

# fmod_result = 1

# Start threads — Do not delete
start_thread(main)

توقيع النسخة#

copysign تُرجع x بإشارة y.

Usage:
math.copysign(x, y)

المعلمة

وصف

x

القيمة المراد تعديلها.

y

القيمة التي سيتم نسخ إشارتها.

def main():
    # Return -10 with the sign of 3 (positive)
    copysign_result = math.copysign(-10, 3)
    console.print(copysign_result)

# copysign_result = 10

# Start threads — Do not delete
start_thread(main)

ldexp#

ldexp يحسب x * (2 ** exp)، وهو ما يعادل x * 2exp.

Usage:
math.ldexp(x, exp)

المعلمة

وصف

x

القيمة الأساسية.

exp

الأس.

def main():
    # Compute 3 * (2 ** 4)
    ldexp_result = math.ldexp(3, 4)
    console.print(ldexp_result)

# ldexp_result = 48

# Start threads — Do not delete
start_thread(main)