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

2 次查看(过去 30 天)
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.

采纳的回答

Sky Sartorius
Sky Sartorius 2017-1-27
编辑:Sky Sartorius 2017-1-27
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by