curve-fitting

Get function handle of fit function in matlab and assign fit parameters

夙愿已清 提交于 2020-01-23 14:02:28
问题 I'm fitting custom functions to my data. After obtaining the fit I would like to get something like a function handle of my fit function including the parameters set to the ones found by the fit. I know I can get the model with formula(fit) and I can get the parameters with coeffvalues(fit) but is there any easy way to combine the two in one step? 回答1: This little loop will do the trick: x = (1:100).'; %' y = 1*x.^5 + 2*x.^4 + 3*x.^3 + 4*x.^2 + 5*x + 6; fitobject = fit(x,y,'poly5'); cvalues =

Get function handle of fit function in matlab and assign fit parameters

左心房为你撑大大i 提交于 2020-01-23 14:02:14
问题 I'm fitting custom functions to my data. After obtaining the fit I would like to get something like a function handle of my fit function including the parameters set to the ones found by the fit. I know I can get the model with formula(fit) and I can get the parameters with coeffvalues(fit) but is there any easy way to combine the two in one step? 回答1: This little loop will do the trick: x = (1:100).'; %' y = 1*x.^5 + 2*x.^4 + 3*x.^3 + 4*x.^2 + 5*x + 6; fitobject = fit(x,y,'poly5'); cvalues =

python fitting curve with integral function

谁都会走 提交于 2020-01-23 11:12:05
问题 I would like to fit data with integral function(truncated gamma distribution). I tried following code, but errors occur. I am appreciate if you would kind help me. Thank you very much in advance. %matplotlib inline import numpy as np from scipy import integrate import scipy.optimize import matplotlib.pyplot as plt xlist=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14] ylist=[1.0, 0.7028985507246377, 0.4782608695652174, 0.36231884057971014, 0.2536231884057971, 0.1811594202898551, 0.12318840579710147, 0

Fitting two curves with linear/non-linear regression

孤街醉人 提交于 2020-01-14 07:51:09
问题 I need to fit two curves(which both should belong to cubic functions) into a set of points with JuMP. I've done fitting one curve, but I'm struggling at fitting 2 curves into same dataset. I thought that if I can distribute points to curves - so if each point can only be used once - I can do it like below, but it didn't work. (I know that I can use much more complicated things, I want to keep it simple.) This is a part of my current code: # cubicFunc is a two dimensional array which accepts

scipy.optimize.curve_fit a definite integral function with scipy.integrate.quad

久未见 提交于 2020-01-14 07:04:13
问题 If I have a function that the independent variable is the upper limit of an definite integral of a mathematical model. This mathematical model has the parameters I want to do regression. This mathematical model is nonlinear and can be complicated. How can I solve this? if the output of my function is then be processed, can it be curve_fit? There is a simplified case import scipy.optimize as sp from scipy.integrate import quad import numpy as np number = 100 def f(x,a,b,c): return 500*a*x+b*c

scipy.optimize.curve_fit a definite integral function with scipy.integrate.quad

谁说我不能喝 提交于 2020-01-14 07:03:44
问题 If I have a function that the independent variable is the upper limit of an definite integral of a mathematical model. This mathematical model has the parameters I want to do regression. This mathematical model is nonlinear and can be complicated. How can I solve this? if the output of my function is then be processed, can it be curve_fit? There is a simplified case import scipy.optimize as sp from scipy.integrate import quad import numpy as np number = 100 def f(x,a,b,c): return 500*a*x+b*c

Fitting a quadratic function in python without numpy polyfit

女生的网名这么多〃 提交于 2020-01-13 09:32:56
问题 I am trying to fit a quadratic function to some data, and I'm trying to do this without using numpy's polyfit function. Mathematically I tried to follow this website https://neutrium.net/mathematics/least-squares-fitting-of-a-polynomial/ but somehow I don't think that I'm doing it right. If anyone could assist me that would be great, or If you could suggest another way to do it that would also be awesome. What I've tried so far: import numpy as np import matplotlib.pyplot as plt import pandas

Fitting a sum to data in Python

谁都会走 提交于 2020-01-13 04:44:34
问题 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

Numba jit with scipy

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-13 03:22:08
问题 So I wanted to speed up a program I wrote with the help of numba jit . However jit seems to be not compatible with many scipy functions because they use try ... except ... structures that jit cannot handle (Am I right with this point?) A relatively simple solution I came up with is to copy the scipy source code I need and delete the try except parts (I already know that it will not run into errors so the try part will always work anyways) However I do not like this solution and I am not sure

Difference between Levenberg-Marquardt-Algorithm and ODR

こ雲淡風輕ζ 提交于 2020-01-12 10:39:52
问题 I was able to fit curves to a x/y dataset using peak-o-mat, as shown below. Thats a linear background and 10 lorentzian curves. Since I need to fit many similar curves I wrote a scripted fitting routine, using mpfit.py, which is a Levenberg-Marquardt-Algorithm. However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result: Starting values Fit result with fixed linear background (values for linear background taken from the peak-o-mat result) Fit result with all