Matias Fernando Mamone
Published © CC BY

Practical Demonstration of Ohm's Law

Water flow is equal to current flow. Is it really, though?

BeginnerFull instructions provided3 hours765
Practical Demonstration of Ohm's Law

Story

Read more

Code

Data analysis and plot

Python
To adapt to your data, just replace the values for heights, times and mass (lines 10, 11, 12).
This script makes a linear fit, a quadratic fit and plots the data. The last five lines make a height prediction based on the time (in seconds) set in line 39 (variable time_set).
# -*- coding: utf-8 -*-
"""
@author: matias mamo
"""

import matplotlib.pyplot as plt
import numpy as np

# Measured values
heights = [0.69, 1.05, 1.42, 1.70, 2.07]
times   = [13*60 + 18, 8*60 + 18, 6*60 + 14, 5*60 + 22, 4*60 + 47]
mass    = 4.605-1.44

# Calculate mass flow
mass_flow = [mass/a for a in times]

# Quadratic fit
p = np.polyfit(mass_flow, heights, 2)
x2 = np.linspace(min(mass_flow), max(mass_flow), 10)
y2 = p[0]*x2**2 + p[1]*x2 + p[2]

# Linear fit
m, b = np.polyfit(mass_flow, heights, 1)
x = np.linspace(min(mass_flow), max(mass_flow), 10)
y = m*x+b

print("The D value is", m, "m*s/kg")

# Generate the graph
plt.cla()
plt.plot(mass_flow, heights, 'o', label="Measured values")
#plt.plot(x2, y2, '--', label="Quadratic fit")
#plt.plot(x, y, '--', label="Linear fit")
plt.xlabel("Mass flow rate (kg/s)")
plt.ylabel("Height of tank 1 (m)")
plt.legend()

# Calculate the height for a 5 minute emptying time
time_set = 300. # 5 minutes
mass = mass # remains the same
mass_flow_set = mass/time_set
height_calculated = m*mass_flow_set + b
print("Calculated height ", height_calculated, " meters", sep="")

Credits

Matias Fernando Mamone

Matias Fernando Mamone

2 projects • 1 follower

Comments