LAB 01 · 120 MIN

Your First Power-Engineering Notebook

أول Notebook في هندسة الطاقة
120 min | 120 دقيقةPhone + KagglePython
On Android/iPhone: choose “Save as PDF” in the print dialog. | على الهاتف اختر «حفظ كملف PDF» من نافذة الطباعة.

Lab goal | هدف المخبر

By the end, every student should have a saved Kaggle Notebook created and executed from a phone, containing Markdown, Python calculations, a NumPy parameter sweep and a Matplotlib figure.

بنهاية المخبر يجب أن يمتلك كل طالب Kaggle Notebook محفوظاً أنشأه وشغّله من الهاتف، ويحتوي على Markdown وحسابات Python ومسح قيم باستخدام NumPy ورسم باستخدام Matplotlib.

120-minute workflow | خطة 120 دقيقة

0–10: Open/rename Notebook and interface check.
فتح Notebook وتسميته والتأكد من الواجهة.

10–25: Code and Markdown cells.
خلايا Code وMarkdown.

25–40: Python variables and MATLAB translation.
المتغيرات والانتقال من MATLAB إلى Python.

40–60: Complex calculation and NumPy sweep.
الحساب العقدي ومسح القيم باستخدام NumPy.

60–75: Indexing and engineering results table.
الفهرسة وبناء جدول النتائج الهندسية.

75–90: Plot and two-case comparison.
الرسم والمقارنة بين حالتين.

90–105: Independent phone investigation.
استقصاء مستقل باستخدام الهاتف.

105–113: Debugging + ChatGPT.
اكتشاف الأخطاء والاستفادة من ChatGPT.

113–120: Save, verify and exit quiz.
الحفظ والتحقق والاختبار الختامي.

📱 STEP 1

Open and prepare Kaggle | افتح Kaggle وجهّز العمل

Open Kaggle Code → New Notebook → rename it PE2_L01_YourName.

افتح Kaggle Code ← اختر New Notebook ← غيّر الاسم إلى PE2_L01_YourName. أبقِ صفحة المخبر في تبويب وKaggle في تبويب آخر.

Task 1 · Markdown cell | المهمة 1 · خلية Markdown

Add a Markdown cell with the course, lab, your name, and the objective: “Study current versus load reactance.”

أضف خلية Markdown تتضمن اسم المقرر والمخبر واسمك والهدف: «دراسة تغير التيار مع مفاعلة الحمل».

Task 2 · First Python cell | المهمة 2 · أول خلية Python

print("Programming in Electrical Power II")
V = 20e3
R = 30
X = 15
print(V, R, X)

Run the cell. Change X once and run it again. Observe that a variable can be reassigned without rewriting the Notebook.

شغّل الخلية، ثم غيّر X مرة واحدة وأعد التشغيل. لاحظ أن قيمة المتغير يمكن تغييرها دون إعادة كتابة الـNotebook.

Task 3 · Translate from MATLAB | المهمة 3 · الانتقال من MATLAB

MATLAB you already know:

الصيغة التي تعرفها مسبقاً في MATLAB:
V = 20e3;
Z = 30 + 1j*15;
I = V/Z;
abs(I)

Now write/run the Python equivalent:

الآن اكتب وشغّل الصيغة المقابلة في Python:
import numpy as np
V = 20e3
Z = 30 + 1j*15
I = V/Z
print(abs(I))
print(np.angle(I, deg=True))

Record |I| and its angle. Explain why the angle is negative.

سجّل مطال التيار وزاويته، واشرح لماذا زاوية التيار سالبة.

Task 4 · NumPy array | المهمة 4 · مصفوفة NumPy

R = 30
X = np.arange(5, 21)
Z = R + 1j*X
I = V/Z

print(X)
print(np.abs(I))

Identify the current at X=5, 15 and 20 Ω. Predict the trend before reading all values.

حدد قيمة التيار عند X=5 و15 و20 Ω. توقّع اتجاه تغير التيار قبل قراءة جميع القيم.

Task 4A · Indexing and engineering extraction | المهمة 4A · الفهرسة واستخراج القيم الهندسية

After creating the X and I arrays, extract the first, middle and last values without retyping the numerical results.

بعد إنشاء مصفوفتَي X وI، استخرج القيم الأولى والوسطى والأخيرة باستخدام الفهرسة دون إعادة كتابة النتائج العددية يدوياً.
print("First:", X[0], np.abs(I[0]))
print("At X=15:", X[10], np.abs(I[10]))
print("Last:", X[-1], np.abs(I[-1]))

Explain why Python uses index 0 for the first element.

اشرح لماذا يستخدم Python الفهرس 0 للعنصر الأول، وقارن ذلك بما تعرفه من MATLAB.

Task 4B · Build an engineering results table | المهمة 4B · بناء جدول نتائج هندسي

Create a compact table showing X, |Z| and |I|. This prepares you for later data-analysis labs.

أنشئ جدولاً صغيراً يعرض X و|Z| و|I|. هذه الخطوة تمهّد للمخابر اللاحقة الخاصة بتحليل البيانات.
for k in range(len(X)):
    print(X[k], np.abs(Z[k]), np.abs(I[k]))

Do not copy all values into the report. Select representative values and describe the trend.

لا تنسخ جميع القيم إلى التقرير. اختر قيماً ممثلة واشرح اتجاه التغير.

Task 5 · First engineering plot | المهمة 5 · أول رسم هندسي

import matplotlib.pyplot as plt

plt.plot(X, np.abs(I), marker="o")
plt.xlabel("Reactance X (ohm)")
plt.ylabel("Current magnitude |I| (A)")
plt.title("Current versus load reactance")
plt.grid(True)
plt.show()

Write two observations below the plot in a Markdown cell.

اكتب ملاحظتين هندسيتين تحت الرسم في خلية Markdown: اتجاه المنحني، والسبب الفيزيائي لهذا الاتجاه.

Task 6 · Small independent change | المهمة 6 · تعديل مستقل صغير

Change R from 30 Ω to 20 Ω. Before running, predict the effect on |I|. Run and compare.

غيّر R من 30 Ω إلى 20 Ω. قبل التشغيل توقّع تأثير ذلك في |I|، ثم شغّل الخلية وقارن النتيجة بتوقعك.

Task 5A · Improve the plot | المهمة 5A · تحسين الرسم

Add a title, units and a second curve for R=20 Ω. Use the same X values so the comparison is meaningful.

أضف عنواناً ووحدات ومنحنى ثانياً للحالة R=20 Ω. استخدم قيم X نفسها حتى تكون المقارنة ذات معنى هندسي.
I30 = V/(30 + 1j*X)
I20 = V/(20 + 1j*X)

plt.plot(X, np.abs(I30), marker="o", label="R=30 ohm")
plt.plot(X, np.abs(I20), marker="s", label="R=20 ohm")
plt.xlabel("Reactance X (ohm)")
plt.ylabel("|I| (A)")
plt.legend()
plt.grid(True)
plt.show()

Write three observations: which curve is higher, why, and whether the gap remains constant.

اكتب ثلاث ملاحظات: أي المنحنيين أعلى؟ لماذا؟ وهل يبقى الفرق بينهما ثابتاً مع تغير X؟

Task 6A · Manual verification | المهمة 6A · التحقق اليدوي

For R=30 Ω, X=15 Ω, calculate |Z| and |I| by hand and compare with Python. Report the absolute difference.

عند R=30 Ω وX=15 Ω احسب |Z| و|I| يدوياً وقارن النتيجة مع Python، ثم سجّل الفرق المطلق بين النتيجتين.
I_python = abs(20e3/(30 + 1j*15))
I_hand = 20000/np.sqrt(30**2 + 15**2)
print("difference =", abs(I_python-I_hand))
📱 INDEPENDENT PHONE TASK · 15 MIN

Mini investigation | استقصاء مصغر

Choose one new resistance R between 10 and 50 Ω. Keep X=5…20 Ω. Generate the current curve and compare it with R=30 Ω. Add a Markdown cell containing your prediction, result and engineering explanation.

اختر بنفسك قيمة جديدة للمقاومة R بين 10 و50 Ω، وأبقِ X من 5 إلى 20 Ω. أنشئ منحني التيار وقارنه بالحالة R=30 Ω. أضف خلية Markdown تتضمن توقعك والنتيجة والتفسير الهندسي.

Rule: the chosen R and written interpretation must be your own.

القاعدة: يجب أن تكون قيمة R المختارة والتفسير المكتوب من عمل الطالب نفسه.

Task 7 · Debugging | المهمة 7 · اكتشاف الأخطاء

V = 20000
R = 30
X = 15
Z = R + X
I = V * Z
print(I)

The code runs, but the engineering model is wrong. Find two conceptual errors before asking AI.

الكود يعمل، لكن النموذج الهندسي خاطئ. اكتشف خطأين مفاهيميين قبل استخدام الذكاء الاصطناعي.
“The code runs but should model Z=R+jX and I=V/Z. Explain what is conceptually wrong without writing the full corrected code.”
«الكود يعمل لكنه يجب أن يمثل Z=R+jX وI=V/Z. اشرح الأخطاء المفاهيمية دون كتابة الكود المصحح كاملاً.»

Required Notebook | الـNotebook المطلوب

Your saved file must contain: title/identity Markdown, scalar calculation, complex current, NumPy X sweep, one labeled plot, two engineering observations, and the corrected debugging cell.

يجب أن يحتوي الملف المحفوظ على: عنوان وبيانات الطالب في Markdown، حساب عددي بسيط، التيار العقدي، مسح X باستخدام NumPy، رسم بمحاور ووحدات، ملاحظتين هندسيتين، وخلية اكتشاف الأخطاء بعد تصحيحها.

Exit quiz | الاختبار الختامي

1. A Code cell is used to:
تستخدم خلية Code من أجل:
2. A Markdown cell is useful for:
تفيد خلية Markdown في:
3. Python comments start with:
تبدأ تعليقات Python بـ:
4. NumPy is imported here as:
يتم استيراد NumPy هنا بالاسم:
5. np.arange(5,21) includes:
يتضمن np.arange(5,21):
6. For an inductive load, Z is:
للحمل الحثي تكون Z:
7. Current is calculated as:
يحسب التيار من:
8. Matplotlib is used to:
تستخدم Matplotlib من أجل:
9. Before running a changed case:
قبل تشغيل حالة معدلة:
10. After ChatGPT explains an error:
بعد شرح ChatGPT للخطأ:
Score | النتيجة: 0/10

References | المراجع

  1. A. Gabash, Flexible Optimal Operations of Energy Supply Networks with Renewable Energy Generation and Battery Storage. Saarbrücken, Germany: Südwestdeutscher Verlag für Hochschulschriften, 2014.
  2. S. J. Russell and P. Norvig, Artificial Intelligence: A Modern Approach, 4th Global ed. Harlow, U.K.: Pearson Education Limited, 2022.
  3. A. Gabash, “Energy Market Transition and Climate Change: A Review of TSOs–DSOs C+++ Framework from 1800 to Present,” Energies, vol. 16, no. 17, Art. no. 6139, 2023, doi: 10.3390/en16176139.
  4. S. J. D. Prince, Understanding Deep Learning. Cambridge, MA, USA: The MIT Press, 2023.
  5. A. Gabash, AI Applications in Electrical Power Systems, Version 1.0, 2026. [Online]. Available: https://aoussgabash.com