-
Notifications
You must be signed in to change notification settings - Fork 114
/
001.3D_Terminal_Voltage_vs_Internal_Resistance_and_Current.py
73 lines (58 loc) · 2.62 KB
/
001.3D_Terminal_Voltage_vs_Internal_Resistance_and_Current.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import sympy as sp
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Given data
delta_V = 2.00 # Change in terminal voltage (in volts)
delta_I = 5.00 # Change in current supplied (in amperes)
# Define variables
R_internal = sp.Symbol('R_internal') # Internal resistance (in ohms)
I = sp.Symbol('I') # Current supplied (in amperes)
V_emf = sp.Symbol('V_emf') # Electromotive force (in volts)
# Ohm's Law: V = E - I * R, where V is terminal voltage, E is emf, and R is internal resistance
equation = sp.Eq(delta_V, V_emf - (I + delta_I) * (R_internal))
# Solve for internal resistance
internal_resistance_solution = sp.solve(equation, R_internal)
# Check if emf can be found
if internal_resistance_solution:
emf_value = sp.solve(sp.Eq(delta_V, V_emf - I * internal_resistance_solution[0]), V_emf)
if emf_value:
emf = float(emf_value[0]) # Convert SymPy expression to float
print(f"Internal Resistance: {internal_resistance_solution[0]} ohms")
print(f"Electromotive Force (emf): {emf} volts")
else:
print("Emf cannot be determined with the given information.")
else:
print("Internal resistance solution not found.")
# Create a Pandas DataFrame for visualization
df = pd.DataFrame({'Internal Resistance (ohms)': np.linspace(0, 10, 100)})
df['Current (A)'] = I_values = np.linspace(0, 10, 100)
df['Terminal Voltage (V)'] = emf - (I_values + delta_I) * df['Internal Resistance (ohms)']
# Convert DataFrame to NumPy arrays
internal_resistance_values = df['Internal Resistance (ohms)'].to_numpy()
terminal_voltage_values = df['Terminal Voltage (V)'].to_numpy()
# Create a 3D plot using Matplotlib
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Create a meshgrid for 3D plot
R_internal_mesh, I_mesh = np.meshgrid(internal_resistance_values, I_values)
delta_V_mesh = emf - (I_mesh + delta_I) * R_internal_mesh # Terminal voltage
# Plot terminal voltage as a surface
ax.plot_surface(R_internal_mesh, I_mesh, delta_V_mesh, cmap='viridis', alpha=0.8)
# Add voltage contours
ax.contour(R_internal_mesh, I_mesh, delta_V_mesh, zdir='z', offset=np.min(delta_V_mesh),
cmap='coolwarm', linewidths=1)
# Add current lines
ax.contour(R_internal_mesh, I_mesh, delta_V_mesh, zdir='y', offset=np.min(I_mesh),
cmap='coolwarm', linewidths=1)
# Set axis labels
ax.set_xlabel('Internal Resistance (Ω)')
ax.set_ylabel('Current (A)')
ax.set_zlabel('Terminal Voltage (V)')
# Add title
ax.set_title('Terminal Voltage vs Internal Resistance and Current')
# Show the 3D plot
plt.show()