Curve fitting with custom function
조회 수: 39 (최근 30일)
이전 댓글 표시
Hello community,
I am trying to do a curve fitting on some experimental data with a custom function. I am more specifically trying to bring closer my function to the data. The function is the following one:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/803864/image.jpeg)
Every parameters of the function, except the shear rate (
) , can vary in order to fit best the data.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/803869/image.jpeg)
Here is a graph with the data and the function plotted with initial values:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/803874/image.jpeg)
The initial values are the following ones:
muInf=0.0035 %[Pa.s]
mu0=0.108; %[Pa.s]
lambda=8.2;
n=0.3;
a=0.64;
viscCar=muInf+(mu0-muInf)*(1+(lambda.*shearRate).^a).^((n-1)/a);
loglog(shearRate,viscCar,'k');
I already tried to use the curve fitting toolbox but i wasn't able to keep the look of the function.
Does anyone know how i can do that ?
Thank you for the help !
댓글 수: 0
채택된 답변
Star Strider
2021년 11월 17일
It would help to have the data.
shearRate = logspace(-3, 4, 100); % Create Data
muv = 0.5-tanh(shearRate)*0.01 + randn(size(shearRate))*0.01; % Create Data
shearRate = shearRate(:);
muv = muv(:);
% muInf=0.0035; %[Pa.s]
% mu0=0.108; %[Pa.s]
% lambda=8.2;
% n=0.3;
% a=0.64;
B0 = [0.0035; 0.108; 8.2; 0.3; 0.64];
viscCar = @(muInf,mu0,lambda,a,n,shearRate) muInf+(mu0-muInf)./(1+(lambda.*shearRate).^a).^((n-1)/a);
viscCarfcn = @(b,shearRate) viscCar(b(1),b(2),b(3),b(4),b(5),shearRate);
mumdl = fitnlm(shearRate,muv, viscCarfcn, B0)
Beta = mumdl.Coefficients.Estimate
figure
loglog(shearRate,viscCarfcn(Beta,shearRate),'k');
hold on
plot(shearRate, muv, '.b')
hold off
grid
This works, and would actually make sense with the actual data.
.
댓글 수: 4
추가 답변 (1개)
Alex Sha
2021년 11월 18일
It is hard to get stable and unique result for Da125's problem, especially for parameters of "lambda" and "n". refer to the result below:
Root of Mean Square Error (RMSE): 0.00032178294087402
Sum of Squared Residual: 2.89923930905092E-6
Correlation Coef. (R): 0.998376698597668
R-Square: 0.996756032302778
Parameter Best Estimate
---------- -------------
muinf -0.0902678665303079
mu0 0.00320052355322768
lambda 207505339.640542
a -0.504386079091155
n -1252.71593136491
댓글 수: 1
Star Strider
2021년 11월 18일
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!