curve-fitting

Scipy curve_fit: how to plot the fitted curve beyond the data points?

与世无争的帅哥 提交于 2019-12-02 11:50:35
I have a number of data points and I used Scipy curve_fit to fit a curve to this data set. I now would like to plot the fit beyond the range of data points and I cannot find out how to do it. Here is a simple example based on an exponential fitting: import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def exponential_fit(x, a, b, c): return a*np.exp(-b*x) + c x = np.array([0, 1, 2, 3, 4, 5]) y = np.array([30, 50, 80, 160, 300, 580]) fitting_parameters, covariance = curve_fit(exponential_fit, x, y) a, b, c = fitting_parameters plt.plot(x, y, 'o', label='data')

`nls` fails to estimate parameters of my model

余生颓废 提交于 2019-12-02 10:25:18
问题 I am trying to estimate the constants for Heaps law. I have the following dataset novels_colection : Number of novels DistinctWords WordOccurrences 1 1 13575 117795 2 1 34224 947652 3 1 40353 1146953 4 1 55392 1661664 5 1 60656 1968274 Then I build the next function: # Function for Heaps law heaps <- function(K, n, B){ K*n^B } heaps(2,117795,.7) #Just to test it works So n = Word Occurrences , and K and B are values that should be constants in order to find my prediction of Distinct Words. I

Fit a B spline to a control path

╄→гoц情女王★ 提交于 2019-12-02 10:17:36
问题 I realise lots of questions and answers exists on the use of B-splines in R, but I have yet to find an answer to this (seemingly simple) question. Given a set of points that describe a control path, how do you fit a B-spline curve to that and extract a given number of points (say 100), along the curve for plotting. The catch is that the path is not monotonous in neither x, nor y. An example control path: path <- data.frame( x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40

Exponential curve fitting without the Curve Fitting toolbox?

只愿长相守 提交于 2019-12-02 08:57:19
问题 I have some data points to which I need to fit an exponential curve of the form y = B * exp(A/x) (without the help of Curve Fitting Toolbox). What I have tried so far to linearize the model by applying log, which results in log(y/B) = A/x log(y) = A/x + log(B) I can then write it in the form Y = AX + B Now, if I neglect B , then I am able to solve it with A = pseudoinverse (X) * Y but I am stuck with values of B ... 回答1: Fitting a curve of the form y = b * exp(a / x) to some data points (xi,

Smooth Hilbert curves

。_饼干妹妹 提交于 2019-12-02 08:49:42
问题 I'm trying to smooth out the path taken by a Hilbert curve. I can define the points and connect them by straight lines, but I want a path that doesn't take the edges so sharply. I attempted to connect the curve using Bezier curves of higher and higher orders but this doesn't work, there are always 'kinks' in the path as I try to reconnect them: I feel like this a solved problem, but I'm not searching for the right terms. 回答1: How about using piecewise cubics for this... Does not really matter

fitting a function with multiple data sets using gnuplot

走远了吗. 提交于 2019-12-02 08:49:25
问题 I would like to fit a function using many data sets. For example, I reproduce an experience many times, each time I obtain a pair of data column (x,y). I put all these column in a file named 'data.txt' : first experience : x = column 1, y = column 2 second experience : x = column 3, y = column 4 third experience : x = column 5, y = column 6 ... Now I wish to fit a function y = f(x) for these data sets. I do not know if Gnuplot can do that ? If it is possible, could you please help me to

Specify clamped knot vector in bs-call

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:34:26
I intend to fit a clamped b-spline to a set of control points in R, but have trouble understanding the use of the knots parameter in bs. Given a set of control points: path <- data.frame( x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40.546875, 36.59375, 34.5, 33.5, 33), y = c(0, 1, 4, 5, 6, 8, 7, 6, 5, 2, 1, 0) ) I fit x and y independently against the distance along the path: path$distance <- c(0, cumsum(sqrt(diff(path[,1])^2 + diff(path[,2])^2))) path$distance ## [1] 0.000000 1.118034 4.344511 9.382259 13.566026 27.766169 41.860284 48.799899 52.877545 56.535931 57.950145 ##

Extracting x value given y threshold from polyfit plot (Matlab)

懵懂的女人 提交于 2019-12-02 08:31:52
As shown by the solid and dashed line, I'd like to create a function where I set a threshold for y (Intensity) from that threshold it gives me corresponding x value (dashed line). Very simple but my while statement is off. Any help would be much appreciated! %% Curve fit plotting %% x1 = timeStamps(1:60); % taking timestamps from 1 - 120 given smoothed y1 values y1 = smooth(tic_lin(1:60),'sgolay',1); % Find coefficients for polynomial (order = 4 and 6, respectively) fitResults1 = polyfit(x1',y1, 7); % evaluate the fitted y-values yplot1 = polyval(fitResults1,x1'); % interpolates to find yi,

Plot vs ggplot2 in R and how to extract fit parameters

情到浓时终转凉″ 提交于 2019-12-02 08:20:49
I have the following data in a data.frame called t DayNum MeanVolume StdDev StdErr 1 13 207.0500 41.00045 5.125057 2 15 142.7625 27.87236 3.484045 3 18 77.5500 19.43928 2.429910 4 21 66.3750 20.56403 2.570504 5 26 67.0500 29.01576 3.626970 6 29 66.4750 25.94537 3.243171 7 33 76.9625 25.31374 3.164218 8 36 91.2875 37.01719 4.627149 9 40 102.0500 29.39898 3.674872 10 43 100.8250 24.22830 3.028538 11 47 120.5125 28.80592 3.600740 12 50 147.8875 35.82894 4.478617 13 54 126.7875 45.43204 5.679004 14 57 139.8500 56.01117 7.001397 15 60 179.1375 69.64526 8.705658 16 64 149.7625 39.10265 4.887831 17

Determining slopes with R code [closed]

自闭症网瘾萝莉.ら 提交于 2019-12-02 07:37:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have a number of melting curves, for which I want to determine the slope of the steepest part between the minimum (valley) and maximum (peak) using R code (the slope in the inflection point corresponds to the melting point). The solutions I can imagine are either to determine the slope in every point and then