How to fit curves with two variables to equation?
7 views (last 30 days)
Show older comments
Amadeus Wolf on 18 Jan 2023
Commented: Amadeus Wolf on 20 Jan 2023
I am struggling quite a while with the problem of getting a formula out of 3 graphs I obtained from simulation.
Below you see the quantity k over normalized concentration for three different velocities.
The velocities vary in the range of 0.001, 0.01 and 0.1.
Using the fit function in matlab, I get a good approximation for the respective curves regarding k in dependency of c/c0.
Now, I want to express k as a function of c/c0 and v. k = f(c/c0,v)
I checked several threads but could not manage to obtain an equation.
My problem is also that the three curves are built up of different sized matrices (165x3 double, 80x3 double and 83x3 double) with different interval size.
Do you have any hints?
William Rose on 18 Jan 2023
Edited: William Rose on 18 Jan 2023
@Amadeus Wolf, please post the data (the three matrices) which you are trying to fit: k and c/c0 and v.
[edit: Remove reference to fmincon(). Add mention of custon function as a fitType. Fix typos.]
On the plot, I recommend distinguishing between the data and the fit.
If you want to use the fit function, then you are fitting a surrface: k is a function of two variables, c/c0 and k. Therefore you cannot use the fourier5 model, which is for functions of one variable only. You can use lowess or loess or polymn models, where m=1 to 5 and n=1 to 5:
where fitType is replaced with loess, lowess, poly11, poly 21, poly12, ..., or poly55.
The diffrent array sizes are not a problem. You can combine your three arrays into a single array with size 245x3, whose columns correspond to c/c0, k, and v.
If none of these fitTypes give a good fit to your three curves, you may have to make your own custom fitType function, and still use fit() to fit it. See here.
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!