Your First Power-Engineering Notebook
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.
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.
الحفظ والتحقق والاختبار الختامي.
Open and prepare Kaggle | افتح Kaggle وجهّز العمل
Open Kaggle Code → New Notebook → rename it PE2_L01_YourName.
Task 1 · Markdown cell | المهمة 1 · خلية Markdown
Add a Markdown cell with the course, lab, your name, and the objective: “Study current versus load reactance.”
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.
Task 3 · Translate from MATLAB | المهمة 3 · الانتقال من MATLAB
MATLAB you already know:
V = 20e3; Z = 30 + 1j*15; I = V/Z; abs(I)
Now write/run the Python equivalent:
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.
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.
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.
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.
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.
Task 6 · Small independent change | المهمة 6 · تعديل مستقل صغير
Change R from 30 Ω to 20 Ω. Before running, predict the effect on |I|. Run and compare.
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.
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.
Task 6A · Manual verification | المهمة 6A · التحقق اليدوي
For R=30 Ω, X=15 Ω, calculate |Z| and |I| by hand and compare with Python. Report the absolute difference.
I_python = abs(20e3/(30 + 1j*15))
I_hand = 20000/np.sqrt(30**2 + 15**2)
print("difference =", abs(I_python-I_hand))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.
Rule: the chosen R and written interpretation must be your own.
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.
«الكود يعمل لكنه يجب أن يمثل 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.
Exit quiz | الاختبار الختامي
References | المراجع
- 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.
- S. J. Russell and P. Norvig, Artificial Intelligence: A Modern Approach, 4th Global ed. Harlow, U.K.: Pearson Education Limited, 2022.
- 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.
- S. J. D. Prince, Understanding Deep Learning. Cambridge, MA, USA: The MIT Press, 2023.
- A. Gabash, AI Applications in Electrical Power Systems, Version 1.0, 2026. [Online]. Available: https://aoussgabash.com