Finding the fitting equation
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Image Analyst
2016년 4월 23일
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
2016년 4월 23일
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.
채택된 답변
Bjorn Gustavsson
2016년 4월 23일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!