Python Forum
Scientific Computing Examples
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scientific Computing Examples
#2
Curve fitting and plotting
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt

x = [20,40,80,160]          # nr of beads (N)
y = [66.7,193,549,1555]     # simulation data ree2

def ree(x, a, v):           # ree = a*N**v
    return a*x**v

popt, pcov = curve_fit(ree, x, y)       # solves variable a and v
a,v = popt                              # v here is 2v

plt.title('High temperature polymer size')
plt.xlabel('nr of beads (N)')
plt.ylabel('r2/a2')
plt.yscale("log")
plt.xscale("log")
plt.plot(x, y , "*",c='black')               # plots discrete points 
plt.grid(True,which="both",ls="-")

xrange = np.array([10,100,1000])
yrange = a*xrange**v

plt.plot(xrange, yrange,c='black') # plots solution of curve fit

print("Parameter v is", popt[1]/2)
Reply


Messages In This Thread
Scientific Computing Examples - by NUMA01 - Sep-25-2020, 12:23 PM
RE: Scientific Computing Examples - by NUMA01 - Sep-25-2020, 01:34 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020