curve-fitting

Using R to fit a curve to a dataset using a specific equation

 ̄綄美尐妖づ 提交于 2019-12-02 03:25:25
I am using R. I would like to use a specific equation to fit a curve to one of my data sets (attached) > dput(data) structure(list(Gossypol = c(1036.331811, 4171.427741, 6039.995102, 5909.068158, 4140.242559, 4854.985845, 6982.035521, 6132.876396, 948.2418407, 3618.448997, 3130.376482, 5113.942098, 1180.171957, 1500.863038, 4576.787021, 5629.979049, 3378.151945, 3589.187889, 2508.417927, 1989.576826, 5972.926124, 2867.610671, 450.7205451, 1120.955, 3470.09352, 3575.043632, 2952.931863, 349.0864019, 1013.807628, 910.8879471, 3743.331903, 3350.203452, 592.3403778, 1517.045807, 1504.491931, 3736

fit multiple parametric curves with scipy

北战南征 提交于 2019-12-02 02:34:28
I have a set (at least 3) of curves (xy-data). For each curve the parameters E and T are constant but different. I'm searching the coefficients a,n and m for the best fit over all curves. y= x/E + (a/n+1)*T^(n+1)*x^m I tried curve_fit, but I have no idea how to get the parameters E and T into the function f (see curve_fit documentation). Furthermore I'm not sure if I understand xdata correctly. Doc says: An M-length sequence or an (k,M)-shaped array for functions with k predictors. What's a predictor? As ydata has only one dimension I obviously can't feed multiple curves into the routine. So

Plotting a histogram with overlaid PDF

巧了我就是萌 提交于 2019-12-01 22:31:40
This is a follow-up to my previous couple of questions. Here's the code I'm playing with: import pandas as pd import matplotlib.pyplot as plt import scipy.stats as stats import numpy as np dictOne = {'Name':['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth'], "A":[1, 2, -3, 4, 5, np.nan, 7, np.nan, 9], "B":[4, 5, 6, 5, 3, np.nan, 2, 9, 5], "C":[7, np.nan, 10, 5, 8, 6, 8, 2, 4]} df2 = pd.DataFrame(dictOne) column = 'B' df2[df2[column] > -999].hist(column, alpha = 0.5) param = stats.norm.fit(df2[column].dropna()) # Fit a normal distribution to the data print

best fitting curve from plot in R

青春壹個敷衍的年華 提交于 2019-12-01 22:12:36
问题 I have a probability density function in a plot called ph that i derived from two samples of data, by the help of a user of stackoverflow, in this way few <-read.table('outcome.dat',head=TRUE) many<-read.table('alldata.dat',head=TRUE) mh <- hist(many$G,breaks=seq(0,1.,by=0.03), plot=FALSE) fh <- hist(few$G, breaks=mh$breaks, plot=FALSE) ph <- fh ph$density <- fh$counts/(mh$counts+0.001) plot(ph,freq=FALSE,col="blue") I would like to fit the best curve of the plot of ph, but i can't find a

Equation of the parabola enclosing a scatter plot

给你一囗甜甜゛ 提交于 2019-12-01 21:46:56
I have the x and y coordinates of the following graph as two different lists s and k. If I want to determine the equation of the parabola that best encloses these points, how do I do it? Thanks! I am not sure how to link to an external data set. What is the best way to add your dataset to a question? This was the best I could find. So, I am putting up a sample data set here. I will be removing this later, though. K S 0 9.500000e-01 -6.500000e-01 1 8.500000e-01 -6.000000e-01 2 9.000000e-01 -6.000000e-01 3 9.500000e-01 -6.000000e-01 4 7.000000e-01 -5.500000e-01 5 7.500000e-01 -5.500000e-01 6 8

Modifying a curve to prevent singular gradient matrix at initial parameter estimates

99封情书 提交于 2019-12-01 17:54:04
I want to use y=a^(b^x) to fit the data below, y <- c(1.0385, 1.0195, 1.0176, 1.0100, 1.0090, 1.0079, 1.0068, 1.0099, 1.0038) x <- c(3,4,5,6,7,8,9,10,11) data <- data.frame(x,y) When I use the non-linear least squares procedure, f <- function(x,a,b) {a^(b^x)} (m <- nls(y ~ f(x,a,b), data = data, start = c(a=1, b=0.5))) it produces an error: singular gradient matrix at initial parameter estimates. The result is roughly a = 1.1466, b = 0.6415, so there shouldn't be a problem with intial parameter estimates as I have defined them as a=1, b=0.5. I have read in other topics that it is convenient to

Exponential curve fit matlab

五迷三道 提交于 2019-12-01 12:22:37
I have the following equation: I want to do a exponential curve fitting using MATLAB for the above equation, where y = f(u,a) . y is my output while (u,a) are my inputs. I want to find the coefficients A,B for a set of provided data. I know how to do this for simple polynomials by defining states. As an example, if states= (ones(size(u)), u u.^2) , this will give me L+Mu+Nu^2 , with L , M and N being regression coefficients. However, this is not the case for the above equation. How could I do this in MATLAB? rayryeng Building on what @eigenchris said, simply take the natural logarithm ( log in

How to find FWHM in a dataset with multiple peaks?

风格不统一 提交于 2019-12-01 12:16:03
问题 I'm using a Python script which finds the indexes of the peaks (or valleys in my case) along a 1D profile, in a specific range of values. My aim is to measure the FWHM for each valley of interest. This is an example of 1D profile This is the script: def detect_peaks (x, mnph=None, mxph=None, mpd=1, threshold=0, edge='rising', kpsh=False, valley=False, show=False, ax=None): #from __future__ import division, print_function import numpy as np x = np.atleast_1d(x).astype('float64') if x.size < 3:

how to find out the scaling factors to match two curves in matlab?

末鹿安然 提交于 2019-12-01 12:05:37
I have two data sets obtained at different days. The results I got from two different data sets have similar shape but different values (see fig1). I am trying to match the second data set (x2,y2) to the first one (x1,y1) by multiply a constant A in x and B in y of the second data (see fig2). for example: data1: x1=[-0.3:0.06:2.1]'; y1=[ 0.001 0.001 0.004 0.014 0.052 0.166 0.330 0.416 0.340 0.247 0.194 0.197 0.237 0.330 0.428 0.542 0.669 0.767 0.855 0.900 0.913 0.904 0.873 0.811 0.765 0.694 0.631 0.585 0.514 0.449 0.398 0.351 0.309 0.273 0.233 0.211 0.182 0.154 0.137 0.117 0.101 ]'; data2 x2=[

Problems fitting to boxcar function using scipy's curvefit in python

点点圈 提交于 2019-12-01 11:27:15
I can't get this boxcar fit working...I get " OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning)" , and the output coefficients are not improved beyond the starting guess. import numpy as np from scipy.optimize import curve_fit def box(x, *p): height, center, width = p return height*(center-width/2 < x)*(x < center+width/2) x = np.linspace(-5,5) y = (-2.5<x)*(x<2.5) + np.random.random(len(x))*.1 coeff, var_matrix = curve_fit(box, x, y, p0=[1,0,2]) The output coefficients are [ 1.04499699, 0., 2.], not that the third one has not even been changed. I