Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Curve fitting for a given function f(x)=a*x+b
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy.optimize import *
- def f(x,a,b):
- return (a*x)+b
- x_given, y_given=np.loadtxt('/storage/emulated/0/shubhadeep roy/ohm_data.txt',delimiter=',',unpack=True)
- params,extras=curve_fit(f,x_given,y_given)
- print("External Resistance= %g KOhm,\nInternal Resistance= %g KOhm"%(params[0],params[1]))
- plt.axis([0,7.0,0,25])
- plt.plot(x_given,y_given,'o')
- plt.plot(x_given,f(x_given,params[0],params[1]),'-r')
- plt.legend(['data','fit'])
- plt.title("Plot of Ohm's Law Experiment's Data")
- plt.ylabel("Potential drop in Volt")
- plt.xlabel("Current in mA")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement