#!/usr/bin/env python # coding: utf-8 # # INVESTIGATION OF THE ENERGY STORED IN A CAPACITOR # # ## Theory # The energy stored by a capacitor is given by the equation: $𝑈= 1/2QV$ Given that $𝑄=𝐶V$ then the equation for the energy stored can be written in the form: $𝑈=1/2 CV_{2}$. The capacitor can be charged to various values of $V$ and then the energy stored can be determined by using a Joule meter. # # The energy stored can be measured as the capacitor discharges. A graph of energy stored against $V^{2}$ should be linear and the value of the capacitance can then be measured. # # # ## Apparatus: # * d.c. power supply # * Voltmeter (multimeter set on d.c. voltage range or CRO) – resolution ± 0.01V # * Digital joule meter # * 4mm leads # * Suitable switches # * Electrolytic capacitors e.g. a 1 000 μF or 2 200 μF # * Resistors e.g. 100 kΩ or other values # # ## Experimental Method: # # ![image.png](attachment:image.png) # # In[1]: # Importing the necessary libraries from matplotlib import pyplot as plt import numpy as np #from prettytable import PrettyTable # Preparing the data to be computed and plotted dt = np.array([ [1.0, 0.15], [2.0, 0.29], [3.0, 0.38], [4.0, 0.50], [5.0, 0.60], [6.0, 0.81], [7.0, 0.90], [8.0, 1.13] ]) # Preparing X and y data from the given data x = dt[:, 0].reshape(dt.shape[0], 1) X = np.append(x, np.ones((dt.shape[0], 1)), axis=1) y = dt[:, 1].reshape(dt.shape[0], 1) # Calculating the parameters using the least square method theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(y) print(f'The parameters of the line: {theta}') # Now, calculating the y-axis values against x-values according to # the parameters theta0 and theta1 y_line = X.dot(theta) # Plotting the data points and the best fit line plt.scatter(x, y) plt.plot(x, y_line, 'r') plt.title('Best fit line using regression method') plt.xlabel('Length in cm') plt.ylabel('Resistance') plt.show() #def makePrettyTable(table_col1, table_col2): # table = PrettyTable() # table.add_column("Column-1", x) # table.add_column("Column-2", Y) #return table # ## Conclusion # In comparison.... # # In[ ]: