data-fitting

Chi-square testing for constraining a parameter

拜拜、爱过 提交于 2019-12-06 06:41:51
I have an important question about the use of chi^2 test to constrain a parameter in cosmology. I appreciate your help. Please do not give this question negative rate (this question is important to me). Assume we have a data file ( data.txt ) concluding 600 data and this data file has 3 columns, first column is redshift(z), second column is observational dL(m_obs) and third column is error(err). As we know chi^2 function is chi^2=(m_obs-m_theo)**2/err**2 #chi^2=sigma((m_obs-m_theo)**2/err**2) from 1 to N=600 All of thing that we must calculate is putting z from given data file into our

Sine wave frequency fitting

雨燕双飞 提交于 2019-12-06 05:23:19
问题 This question is based on a previous similar question. I have the following equation and an adjusted (some random data): 0.44*sin(N* 2*PI/30) I am trying to use the FFT to get the frequency from the data generated. However the frequency ends up being close but not equal to the frequency (which makes the wave a bit larger than intended) The frequencies that are at the maximum for the FFT is 7hz, however the expected frequency is (30/2PI) 4.77hz. I've included a graph of the FFT and plotted

Transform data to fit normal distribution

♀尐吖头ヾ 提交于 2019-12-06 03:23:54
I have a rather easy-to-understand question. I have a set of data and I want to estimate how good this data fit a standard normal distribution . To do so, I start with my code: [f_p,m_p] = hist(data,128); f_p = f_p/trapz(m_p,f_p); x_th = min(data):.001:max(data); y_th = normpdf(x_th,0,1); figure(1) bar(m_p,f_p) hold on plot(x_th,y_th,'r','LineWidth',2.5) grid on hold off Fig. 1 will look like the one below: Easy to see that the fit is quite poor, altough the bell-shape can be spotted. The main problem resides therefore in the variance of my data. To find out the proper number of occurrances my

Fit a distribution to a histogram

孤者浪人 提交于 2019-12-06 02:59:42
问题 I want to know the distribution of my data points, so first I plotted the histogram of my data. My histogram looks like the following: Second, in order to fit them to a distribution, here's the code I wrote: size = 20000 x = scipy.arange(size) # fit param = scipy.stats.gamma.fit(y) pdf_fitted = scipy.stats.gamma.pdf(x, *param[:-2], loc = param[-2], scale = param[-1]) * size plt.plot(pdf_fitted, color = 'r') # plot the histogram plt.hist(y) plt.xlim(0, 0.3) plt.show() The result is: What am I

Fitting a curve with a pivot point Python

不打扰是莪最后的温柔 提交于 2019-12-05 21:03:20
I have the plot below and I want to fit it with 2 lines. Using python I manage to fit the upper part: def func(x,a,b): x=np.array(x) return a*(x**b) popt,pcov=curve_fit(func,up_x,up_y) And I want to fit the lower part with another line, but I want the line to pass through the point where the red one stars, so I can have a continuous function. So my question is how can I use curve_fit by giving a point the function has to pass through, but leaving the slope of the line to be calculated by python? (Or any other python package able to do it) A possible stepwise parametrisation of your model in

plot 3D line, matlab

为君一笑 提交于 2019-12-05 19:54:20
My question is pretty standard but can't find a solution of that. I have points=[x,y,z] and want to plot best fit line. I am using function given below (and Thanx Smith) % LS3DLINE.M Least-squares line in 3 dimensions. % % Version 1.0 % Last amended I M Smith 27 May 2002. % Created I M Smith 08 Mar 2002 % --------------------------------------------------------------------- % Input % X Array [x y z] where x = vector of x-coordinates, % y = vector of y-coordinates and z = vector of % z-coordinates. % Dimension: m x 3. % % Output % x0 Centroid of the data = point on the best-fit line. %

fit a function to a histogram created with frequency in gnuplot

末鹿安然 提交于 2019-12-05 17:48:12
Intro In gnuplot there's a solution to create histogram from file named hist.dat what likes 1 2 2 2 3 by using commands binwidth=1 set boxwidth binwidth bin(x,width)=width*floor(x/width) + binwidth/2.0 plot [0:5][0:*] "hist.dat" u (bin($1,binwidth)):(1.0) smooth freq with boxes that generates a histogram like this one from other SO page . Question How can I fit my function to this histogram? I defined a Gaussian function and initialized its values by f(x) = a*exp(-((x-m)/s)**2) a=3; m=2.5; s=1 and in the output the function follow the histogram well. Unfortunatelly I cannot fit to this

Simultaneous data fitting in python with leastsq

流过昼夜 提交于 2019-12-05 07:21:42
问题 I didn't program for a long time and never was good at it, but it is kind of important task I am struggling with. I am trying to fit two sets of data (x – time, y1 and y2 – different columns of values which should be read from text file). For each dataset (y1 and y2) I have a function which should fit them. Inside both of the functions I have several parameters to be fitted. For some time values the data for "y" is absent, so the task is to program it somehow when “y” is missing and fit the

Fitting a sum to data in Python

旧城冷巷雨未停 提交于 2019-12-04 16:24:33
Given that the fitting function is of type: I intend to fit such function to the experimental data (x,y=f(x)) that I have. But then I have some doubts: How do I define my fitting function when there's a summation involved? Once the function defined, i.e. def func(..) return ... is it still possible to use curve_fit from scipy.optimize? Because now there's a set of parameters s_i and r_i involved compared to the usual fitting cases where one has few single parameters. Finally are such cases treated completely differently? Feel a bit lost here, thanks for any help. This is very well within reach

Fitting data to system of ODEs using Python via Scipy & Numpy

一曲冷凌霜 提交于 2019-12-04 14:01:40
问题 I am having some trouble translating my MATLAB code into Python via Scipy & Numpy. I am stuck on how to find optimal parameter values (k0 and k1) for my system of ODEs to fit to my ten observed data points. I currently have an initial guess for k0 and k1. In MATLAB, I can using something called 'fminsearch' which is a function that takes the system of ODEs, the observed data points, and the initial values of the system of ODEs. It will then calculate a new pair of parameters k0 and k1 that