multiple variables fitting with lsqnonlin
Ältere Kommentare anzeigen
my curve fitting with lsqnonlin has poor fit. what is wrong?
clear;
X0 = [0.1; 0.1; 0.1; 0.1];
no = 520;
no_data = 520;
H_total = 0;
time = load('time_BS19.m');
dqdt = load('Q_BS19.m');
temp = load('temp_BS19.m');
baseline = zeros(no,1);
alpha = zeros(no,1);
dadt = zeros(no,1);
gradient = ( dqdt(no,1) - dqdt(1,1) ) / ( time(no,1) - time(1,1) );
for i = 1 : no
baseline(i,1) = dqdt(1,1) + gradient * ( time(i,1) - time(1,1) );
end
for i = 2 : no
H_total = H_total + ( dqdt(i,1) - baseline(i,1) ) * ( time(i,1) - time(i-1,1) ) ;
end
for i = 2 : no
alpha(i,1) = alpha(i-1,1) + ( ( dqdt(i,1) - baseline(i,1) ) * ( time(i,1) - time(i-1,1) ) ) / H_total;
end
for i = 1 : no
dqdt(i,1) = dqdt(i,1) - baseline(i,1);
end
for i = 1 : no
dadt(i,1) = dqdt(i,1) / H_total;
end
for i = 1 : no_data
X(i,1) = alpha( (i-1)*1+1 ,1);
Y(i,1) = dadt( (i-1)*1+1 ,1);
end
X(1,1) = alpha(1,1)+0.00001;
X(no_data,1) = alpha(no,1)-0.00001;
Y(no_data,1) = dadt(no,1);
options = optimset ('Largescale','off');
x=lsqnonlin(@fitting_epoxy_isothermal,X0,[],[],options,X,Y);
xt=real(x);
x=xt;
Y_sim = ( x(1) + x(2) * (alpha).^ x(3)).* ( 1-alpha).^ (x(4));
alpha_sim(1,1) = 0;
for i = 2 : no
alpha_sim(i,1) = alpha_sim(i-1,1) + Y_sim(i,1) * ( time(i,1) - time(i-1,1) ) ;
end
sr=187.5; % shear rate (s^-1)
macosko_0=[3*10^(-9), 6000, 10^(9), 0.2, 0.6, 2, -0.1]; % B, Tb, tau*, n, alpha_g(>alpha), c1, c2
no_ext=702; % alpha > 0 이 되는 부분 앞으로 배열요소 확장(점도측정 시작지점)
temp_ext=load('temp_BS19_ext.m');
alpha_ext=zeros(no_ext,1);
time_ext=load('time_BS19_ext.m');
eta_ext=load('eta_BS19_ext.m');
temp_ext=temp_ext+273.15;
for i=1:(no_ext-no)
alpha_ext(i)=0;
end
for i=(no_ext-no+1):no_ext % 배열요소 확장
alpha_ext(i)=alpha(i-(no_ext-no));
end
options = optimset ('Largescale','off','Display','iter');
% options = optimset ('FunValCheck','on');
%[macosko] = lsqnonlin(@(macosko)fitting_macosko(macosko,temp_ext,alpha_ext,eta_ext),macosko_0);
macosko=lsqnonlin(@fitting_macosko,macosko_0,[],[],options,temp_ext,alpha_ext,eta_ext);
mt=real(macosko);
macosko=mt;
eta_sim=zeros(no_ext,1);
% eta_sim=macosko(1)*exp(macosko(2)./temp_ext)./(1+(macosko(1)*exp(macosko(2)./temp_ext)*sr/macosko(3))).^(1-macosko(4)).*(macosko(5)/(macosko(5)-alpha_ext)).^(macosko(6)+macosko(7).*alpha_ext);
for i=1:no_ext
eta_sim(i) = macosko(1)*exp(macosko(2)./temp_ext(i))./(1+((macosko(1)*exp(macosko(2)./temp_ext(i))*sr/macosko(3)).^(1-macosko(4)))).*(macosko(5)/(macosko(5)-alpha_ext(i))).^(macosko(6)+macosko(7).*alpha_ext(i));
end
plot3(temp_ext,alpha_ext,eta_ext,'bo')
hold on
plot3(temp_ext',alpha_ext,eta_sim,'r')
figure(5)
semilogy(temp_ext, eta_ext, 'bo', temp_ext, eta_sim, 'r')
xlabel('temp (K)');
ylabel('viscosity (Pa.s)');
% grid on;
my objective function is
function parameters = fitting_epoxy_isothermal(x,X,Y)
parameters = ( x(1) + x(2) * X.^ x(3) ).* ( 1-X ).^ (x(4)) - Y;
function parameter = fitting_macosko(macosko,temp_ext,alpha_ext,eta_ext) % alpha_rheo 의 앞 배열을 0으로 확장 필요
sr=187.5; % shear rate (s^(-1)) 기입
parameter = macosko(1)*exp(macosko(2)./temp_ext)./(1+((macosko(1)*exp(macosko(2)./temp_ext)*sr/macosko(3)).^(1-macosko(4)))).*(macosko(5)/(macosko(5)-alpha_ext)).^(macosko(6)+macosko(7).*alpha_ext)-eta_ext;
5 Kommentare
Yongchul Shin
am 27 Sep. 2019
Yongchul Shin
am 27 Sep. 2019
Yongchul Shin
am 27 Sep. 2019
Adam Danz
am 27 Sep. 2019
Sorry, that's too much copy-pasting and variable naming for me. If the data are attached so I can load them using your code, I can take a look at it.
Antworten (1)
Yongchul Shin
am 27 Sep. 2019
0 Stimmen
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!