Unable to perform curve fitting
2 views (last 30 days)
Show older comments
Hello everyone,
I have been struggling for a while doing a nonlinear regression to a simple set of data. I wanted to perform it with the curve fitting tooldbox, but somehow it can't fit the data to my model equasion.
I have my custom equasion of this type: (a*(0.03^2)+b*0.03+c)*(exp(-d*x)+f*exp(-g*x)) and as a result i get:
I have also tried with nlinfit and fitnlm functions but the results are super sensitive on the initial values for the parameters which leads to unacurate results for a,b,c,d,f and g.
The final idea is to use the calculated model parameters and then define new calues for my Deff (Coefficient of effective diffusion) with different values for ksi (hydromodule)
clc;
clear all;
ksi=0.03;
tao=[300 600 900 1200 1800 3600 5400 7200 27000];
DeRR=[3.90592997493998e-09 2.35848864487335e-09 1.84176664779469e-09 1.58252065132943e-09 1.32075697832129e-09 1.03628002341392e-09 8.81177774572414e-10 7.28508407391888e-10 2.00749829156030e-10];
beta0=[0 0 0 0 0 0];
stupid=@(a,tao)(a(1)*(ksi^2)+a(2)*ksi+a(3))*((exp(-a(4)*tao)+a(5)*exp(-a(6)*tao)));
beta = nlinfit(tao,DeRR,stupid,beta0);
a(1)=beta(1);
a(2)=beta(2);
a(3)=beta(3);
a(4)=beta(4);
a(5)=beta(5);
a(6)=beta(6);
ksin=[0.01];
Dcal=(a(1).*(ksin.^2)+(a(2).*ksin)+a(3)).*((exp(-a(4).*tao)+(a(5).*exp(-a(6).*tao))));
plot(tao,DeRR,'ko',tao,Dcal,'b-')
legend('Data','Deff 0.01','Deff 0.02')
title('Deff')
I would appreciate any suggestions regarding to the curve fitting toolbox (how to work with my model equasion) or the script, because i am writing a bachelor thesis.
Thank you very much in advance!
1 Comment
Alex Sha
on 2 Sep 2020
Hi, Niya, first of all, there is a problem with your fitting function, the part of "(a(1)*(ksi^2)+a(2)*ksi+a(3))" can be substitued by "a(1)*(ksi^2)", otherwise, parameters of a(1), a(2) and a(3) will not be stable, that is there will have infinite cobminations among them. So if fitting function become DeRR=a1*(ksi^2)*((exp(-a4*tao)+a5*exp(-a6*tao))), the unique result could be obtained as below:
Root of Mean Square Error (RMSE): 4.80014676010325E-11
Sum of Squared Residual: 2.07372680266768E-20
Correlation Coef. (R): 0.998998426725134
R-Square: 0.997997856599293
Adjusted R-Square: 0.997330475465725
Parameter Best Estimate
---------- -------------
a1 6.61536444129772E-6
a4 0.00304744048933963
a5 0.260714360113999
a6 0.000101021724906286
Answers (0)
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox 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!