Questions tagged [curve-fitting]

Fitting 1-D curve to data points, minimizing pre-defined error/loss function.

From wiki:

Curve fitting is the process of constructing a curve, or mathematical function, that has the best fit to a series of data points.

3428 questions
10
votes
5 answers

How to fit a polynomial with some of the coefficients constrained?

Using NumPy's polyfit (or something similar) is there an easy way to get a solution where one or more of the coefficients are constrained to a specific value? For example, we could find the ordinary polynomial fitting using: x = np.array([0.0, 1.0,…
Jenny Shoars
  • 994
  • 3
  • 16
  • 40
10
votes
1 answer

applying "tighter" bounds in scipy.optimize.curve_fit

I have a dataset that I am trying to fit with parameters (a,b,c,d) that are within +/- 5% of the true fitting parameters. However, when I do this with scipy.optimize.curve_fit I get the error "ValueError: 'x0' is infeasible." inside the least…
Austin Downey
  • 943
  • 2
  • 11
  • 28
10
votes
2 answers

Ratio of polynomials approximation

I am trying to fit a polynomial to my dataset, which looks like that (full dataset is at the end of the post): The theory predicts that the formulation of the curve is: which looks like this (for x between 0 and 1): When I try to make a linear…
marco11
  • 235
  • 2
  • 8
10
votes
3 answers

Stretching out an array

I've got a vector of samples that form a curve. Let's imagine there are 1000 points in it. If I want to stretch it to fill 1500 points, what is the simplest algorithm that gives decent results? I'm looking for something that is just a few lines…
twk
  • 16,760
  • 23
  • 73
  • 97
10
votes
3 answers

How to properly fit a beta distribution in python?

I am trying to get a correct way of fitting a beta distribution. It's not a real world problem i am just testing the effects of a few different methods, and in doing this something is puzzling me. Here is the python code I am working on, in which I…
Jason
  • 2,950
  • 2
  • 30
  • 50
10
votes
4 answers

Sine curve fit using lm and nls in R

I am a beginner in curve fitting and several posts on Stackoverflow really helped me. I tried to fit a sine curve to my data using lm and nls but both methods show a strange fit as shown below. Could anyone point out where I went wrong. I would…
Eddie
  • 783
  • 4
  • 12
  • 24
10
votes
3 answers

Fitting sigmoid to data

There are many curve fitting and interpolation tools like polyfit (or even this nice logfit toolbox I found here), but I can't seem to find anything that will fit a sigmoid function to my x-y data. Does such a tool exist or do I need to make my…
lollercoaster
  • 15,969
  • 35
  • 115
  • 173
10
votes
3 answers

Fitting an unknown curve

There are some related questions that I've come across (like this, this, this, and this) but they all deal with fitting data to a known curve. Is there a way to fit given data to an unknown curve? By which I mean, given some data the algorithm will…
Kitchi
  • 1,874
  • 4
  • 28
  • 46
10
votes
5 answers

How to fit a gaussian to data in matlab/octave?

I have a set of frequency data with peaks to which I need to fit a Gaussian curve and then get the full width half maximum from. The FWHM part I can do, I already have a code for that but I'm having trouble writing code to fit the Gaussian. Does…
user1806676
  • 169
  • 1
  • 1
  • 10
10
votes
3 answers

Fitting a line that passes through the origin (0,0) to data

I have a set of points (x,y) and I need to find the line of best-fit that passes through the origin using MATLAB.
dr_rk
  • 4,395
  • 13
  • 48
  • 74
10
votes
1 answer

I know scipy curve_fit can do better

I'm using python/numpy/scipy to implement this algorithm for aligning two digital elevation models (DEMs) based on terrain aspect and slope: "Co-registration and bias corrections of satellite elevation data sets for quantifying glacier thickness…
David Shean
  • 1,015
  • 1
  • 9
  • 11
10
votes
2 answers

Need to fit polynomial using chebyshev polynomial basis

I have been fitting linear least-squares polynomials to data using the polyfit function in matlab. From what I read, this uses standard polynomial basis (monomial basis). I have read that using Chebyshev polynomial basis to fit leads to greater…
user1593853
  • 127
  • 1
  • 1
  • 7
10
votes
2 answers

Use of curve_fit to fit data

I'm new to scipy and matplotlib, and I've been trying to fit functions to data. The first example in the Scipy Cookbook works fantastically, but when I am trying it with points read from a file, the initial coefficients I give (p0 below) never seem…
Ironil
  • 171
  • 2
  • 2
  • 12
9
votes
5 answers

How can I find equation of a plot connecting data points in Matlab?

I have various plots (with hold on) as show in the following figure: I would like to know how to find equations of these six curves in Matlab. Thanks.
user238469
9
votes
1 answer

How to do a polynomial fit with fixed points in 3D

I have sets of x,y,z points in 3D space and another variable called charge which represents the amount of charge that was deposited in a specific x,y,z coordinate. I would like to do a weighted (weighted by the amount of charge deposited in the…