How do i fit my data with two functions and a knot between them

2 Ansichten (letzte 30 Tage)
I am trying to fit the data in the graph below. The fit should be composed of two functions.
f(x) for x<k
g(x) for x>k
I do not know if it is needed but this are the two functions:
f(x) = 3/4*b*((a-x)/a-(a-x)^3/3a^3+2/3)+c
g(x) = d
The function g(x) is just a constant line and should fit the data approximately between 3.5 and 7. a,b and c are parameters of the fit.

Akzeptierte Antwort

Sky Sartorius
Sky Sartorius am 27 Jan. 2017
Bearbeitet: Sky Sartorius am 27 Jan. 2017
The tanh function can be handy for creating a one-liner piece-wise function for feeding into a curve fitting tool. If you don't have the curve fitting toolbox, check out https://www.mathworks.com/matlabcentral/fileexchange/10176. In the ezfit tool, I can ask it to fit my own equation of the form:
(0.5-tanh((x-k)/eps)/2)*(F1) + (0.5+tanh((x-k)/eps)/2)*(F2);
In your case, replace F1 and F2 with your fit functions:
(0.5-tanh((x-k)/eps)/2)*(3/4*b*((a-x)/a-(a-x)^3/3*a^3+2/3)+c) + (0.5+tanh((x-k)/eps)/2)*(d);
You can also get some a priori information from your data that will help constrain the problem and help it converge to a good fit, for example you can bound d to be between the min and max of your data y values, and similarly for k and the data x values.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by