3D curvefitting

To fit a curve onto a set of points, we can use ordinary least-squares regression. There is a solution page by MathWorks describing the process. As an example, let’s start with some random data: % some 3d points data = mvnrnd([0 0 0], [1 -0.5 0.8; -0.5 1.1 0; 0.8 0 1], 50); As @BasSwinckels … Read more

Curve Fitting to a time series in the format ‘datetime’?

Instead of plotting datenums, use the associated datetimes. import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import datetime as DT import time dates = [DT.datetime(1978, 7, 7), DT.datetime(1980, 9, 26), DT.datetime(1983, 8, 1), DT.datetime(1985, 8, 8)] y = [0.00134328779552718, 0.00155187668863844, 0.0039431374327427, 0.00780037563783297] yerr = [0.0000137547160254577, 0.0000225670232594083, 0.000105623642510075, 0.00011343121508] x = mdates.date2num(dates) … Read more

Java curve fitting library [closed]

Apache Commons Math has a nice series of algorithms, in particular “SplineInterpolator”, see the API docs An example in which we call the interpolation functions for alpha(x), beta(x) from Groovy: package example.com import org.apache.commons.math3.analysis.interpolation.SplineInterpolator import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction import statec.Extrapolate.Value; class Interpolate { enum Value { ALPHA, BETA } def static xValues = [ -284086, -94784, 31446, … Read more

Fit sigmoid function (“S” shape curve) to data using Python

After great help from @Brenlla the code was modified to: def sigmoid(x, L ,x0, k, b): y = L / (1 + np.exp(-k*(x-x0))) + b return (y) p0 = [max(ydata), np.median(xdata),1,min(ydata)] # this is an mandatory initial guess popt, pcov = curve_fit(sigmoid, xdata, ydata,p0, method=’dogbox’) The parameters optimized are L, x0, k, b, who are … Read more

How to fit a smooth curve to my data in R?

I like loess() a lot for smoothing: x <- 1:10 y <- c(2,4,6,8,7,12,14,16,18,20) lo <- loess(y~x) plot(x,y) lines(predict(lo), col=”red”, lwd=2) Venables and Ripley’s MASS book has an entire section on smoothing that also covers splines and polynomials — but loess() is just about everybody’s favourite.