All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
1. What does popt and pcov mean? The curve_fit function returns two items, which we call popt and pcov.The popt argument are the best fit for 'a' and 'b'. The pcov variable contains the covariance matrix which indicates the uncertainties and corelation between parameters. This is mostly useful when the data has uncertainties.…
Rajiv Ranjan
updated on 30 Jun 2021
1. What does popt and pcov mean?
The curve_fit function returns two items, which we call popt and pcov.The popt argument are the best fit for 'a' and 'b'. The pcov variable contains the covariance matrix which indicates the uncertainties and corelation between parameters. This is mostly useful when the data has uncertainties.
2. What does np.array(temperature) do?
This function stores the value of the temperature in the form of an array passes it to the function numpy.
3. What does the * in *popt mean?
popt contains the value for 'a' 'b' and 'c' and using the * we are referring to these value.
4. Write code to fit a linear and cubic polynomial for the Cp data. Explain if your results are good or bad.
We will start the code with importing the modules.
import numpy as np
import matplotlib.pyplot as plt
#from scipy.optimize import curve_fit
A function is defined consisting of linear equation
#Curve fit function
def func(t, a, b):
return a*t + b
#Reading thermodynamics data file
def read_file():
temperature = []
cp = []
for line in open('data','r'):
values = line.split(',')
temperature.append(float(values[0]))
cp.append(float(values[1]))
return [temperature, cp]
#Main Program
temperature, cp = read_file()
a = 0
b = 399
fit_cp = []
for i in range(0,8):
c = temperature[a:b+1]
d = cp[a:b+1]
popt, pcov = curve_fit(func, c, d)
z = func(np.array(c), *popt)
for j in z:
fit_cp.append(j)
a = b + 1
b = b + 400
plt.figure()
plt.plot(temperature, cp, color = 'green')
plt.plot(temperature, fit_cp, color = 'red')
plt.legend(['Actual data','curve fit'])
plt.xlabel('temperature [k]')
plt.ylabel('cp')
plt.show()
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week 3 - Solving second order ODEs
import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt import math # function that returns dz/dt def model(theta,t,b,g,l,m): theta1 = theta [0] theta2 = theta [1] dtheta1_dt = theta2 dtheta2_dt = -(b/m)*theta2 - (g/l)* math.sin(theta1) dtheta_dt = [dtheta1_dt,dtheta2_dt] return dtheta_dt…
01 Jul 2021 03:33 AM IST
Week 6 - Data analysis
import matplotlib.pyplot as plt import numpy as np from numpy import trapz fname = input("Enter the filename: ") if fname == 'engine_data.out': print('file is valid') else: print('file is invalid') exit() def compatibility_check(a): if 'CONVERGE' not in a: print('please provide converge output file to process') exit()…
30 Jun 2021 12:37 PM IST
Week 5 - Curve fitting
1. What does popt and pcov mean? The curve_fit function returns two items, which we call popt and pcov.The popt argument are the best fit for 'a' and 'b'. The pcov variable contains the covariance matrix which indicates the uncertainties and corelation between parameters. This is mostly useful when the data has uncertainties.…
30 Jun 2021 12:31 PM IST
Week 2 Air standard Cycle
INTRODUCTION: - The Otto cycle is the theoretical cycle of interest when one is considering reciprocating SI engines. The four-stroke Otto cycle is made up of the following four internally reversible processes: 1–2, isentropic compression; 2–3, constant-volume heat addition; 3–4, isentropic…
19 May 2021 10:07 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.