How to curve fit using two functions in two different data segment
18 views (last 30 days)
Dear Matlab users,
I have two set of data points, first 200 (y, x3) and second 200 (y, x1) to fit using two non-linear functions, f(x1, x2, x3) and g(x1,x2,x3). The figure is attached below.
Fitting cases: if 0.3 < x3 < 1.0, then a non-linear function f(x1,x2,x3) is to be used to fit the data. Here x1 = x2 = 1/sqrt(x3).
If 1.0 < x1,x2 < 1.7, then a combination of non-linear functions f(x1,x2,x3) + g(x1,x2,x3) is to be used, Here x1 = x2 and x3 = 1/(x1x2) and the function f(x1,x2,x3) is same in both except it takes x1 argument.
I have already fit the two data set separately using lsqcurvefit. However, how could it be possible to combine these two fitting procedure in a single Matlab fit so that f(x1, x2, x3) participates to describe both the data points between 0.3 < x < 1.7 and g(x1, x2, x3) participates only when 1.0 < x < 1.7?
Many thanks in advance.
William Rose on 8 Apr 2022
Yes, it is possible and not too difficult. YOu just need to write the error function, or cost function, appropriately. However, the problem a yo have described it is not clear. Please post your data. Please specifiy the functions f(x,y,z) and g(x,y,z). Please be sure to distinguih clearly beteeen the independent variable and the adjustable parameters.
You said points are (y, x3), and points 201-400 are (y, x1). You also said
"a non-linear function f(x1,x2,x3) is to be used to fit the data. Here x1 = x2 = 1/sqrt(x3)"
If both of those statements are true, then there are no adjustable parameters for the f() function: x3 is the independent variable, and you cannot change it. x2 and x1 are defined in terms of x3, according to your statement, so you can;t change them either.
You said you use f() if 0<x1,x2<1.3, and want to fit it with f()+g(). And you said the x1, x2, x3 are the same But in th case of f(x1,x2,x3) there is really only one parameter, as I just described, so it is not clear what can be adjusted for g(x1,x2,x3).
You said "if 0.3 < x3 < 1.0, then a non-linear function f(x1,x2,x3) is to be used to fit the data"
and you said
"if 1.0 < x1,x2 < 1.7, then a combination of non-linear functions f(x1,x2,x3) + g(x1,x2,x3) is to be used"
If x1, x2, x3 are separetely adjustable, then you could satisfy both the first and the second conditions simultaneously. In that case, which function or functions should be used?
Please think about how you can restate the pobem more clearly. Post the specific data you want to fit. Specify the functions f() and g(). Distinguish clearly between independent variables (which you cannot adjust) and parameters (which you can adjust to fit the data).
Good luck with your work.