Advertisement
Guest User

Curve fittingOhmsLaw.py

a guest
Aug 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #Curve fitting for a given function f(x)=a*x+b
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from scipy.optimize import *
  5. def f(x,a,b):
  6.        return (a*x)+b
  7.  
  8. x_given, y_given=np.loadtxt('/storage/emulated/0/shubhadeep roy/ohm_data.txt',delimiter=',',unpack=True)
  9. params,extras=curve_fit(f,x_given,y_given)
  10. print("External Resistance= %g KOhm,\nInternal Resistance= %g KOhm"%(params[0],params[1]))
  11. plt.axis([0,7.0,0,25])
  12. plt.plot(x_given,y_given,'o')
  13. plt.plot(x_given,f(x_given,params[0],params[1]),'-r')
  14. plt.legend(['data','fit'])
  15. plt.title("Plot of Ohm's Law Experiment's Data")
  16. plt.ylabel("Potential drop in Volt")
  17. plt.xlabel("Current in mA")
  18. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement