Finding the fitting equation
1 view (last 30 days)
Show older comments
I have some experiential data points as the attached file. How can I find a fitting equation for this data following a form below
2 Comments
Image Analyst
on 23 Apr 2016
What are the independent variables? T and P? What are the parameters to estimate? The A? What data do you have to train the regression?
Star Strider
on 23 Apr 2016
Before I download the file, please supply some details about the model:
- What variables are your data?
- What variables are the parameters you’re estimating?
The format for an objective function to give to the nonlinear solvers is:
fcn = @(prmv, indep_var) ...;
so if you were solving for a straight-line fit ‘y=m*x+b’, the function would be:
fcn = @(prmv,indep_var) prmv(1).*indep_var + prmv(2);
where ‘prmv’ is the parameter vector, and ‘indep_var’ is your independent variable. (You can call them whatever you like. The function just has to conform to this format.)
It would be easier for you to write your objective function as an anonymous function than a function file. If you have two independent variables, put them together in a matrix, and pass the matrix as one argument to your function. You can split them apart inside your function.
Accepted Answer
Bjorn Gustavsson
on 23 Apr 2016
After reading your previous question about this your first line of action is to read some introduction to matlab/getting started with matlab and then go to the documentation for fminsearch. This might come off as a bit rude but nothing beats having a solid understanding of the basics.
Given that, the steps you should make are: 0, load you data... 1, create a function z_of_PnT - either as a proper m-file or as a dynamic function. Here I'll do the former, (this might come at some efficiency cost):
z_fcn = @(A,P,T) 1 +A(1)*P + A(2)*P.^2 + A(3)*P.^A(4)./T.^A(5)+ A(6)*P.^(A(4)+1)./T.^A(7) + A(8)*P.^(A(4)+2)./T.^(A(7)+1);
Then to estimate the parameters in A you have to make yourself some error-function, here I'll use the simplest sum-of-square (This you'll have to adjust after needs and situation (different uncertainties of different data-points, specific statistical characteristics of your measurement system)):
err_fcn = @(A,fcn,y) sum((fcn(A)-y).^2);
Then you should convert your function z_fcn to a function of A only:
fit_fcn = @(A) z_fcn(A,Ppr,Tpr); % using the variable names from your file
This step you can omit, but then you'd have to change to definition of err_fcn to match.
The search for your best fitting parameters in A you do with fminsearch, here I've got no idea about what might be a good start-guess for the different components in A, so I'll simply guess they're all equal to one:
Afitted = fminsearch(@(A) err_fcn(A,fit_fcn,Z),ones(1,8));
This doesn't converge too well so you ought to either use a better start-guess or simply repeat the fitting until the fitting is good enough.
Instead of fminsearch you can also use lsqnonlin with the appropriate changes of the input functions.
HTH
0 Comments
More Answers (0)
See Also
Categories
Find more on Gaussian Process 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!