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

조회 수: 4 (최근 30일)
artu' breuer
artu' breuer 2017년 1월 27일
댓글: artu' breuer 2017년 2월 6일
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