How do I fit multiple curves with same fitting parameters?

12 views (last 30 days)
I am trying to fit this expression: the τ's are stress variables for three different temperatures. I have tried the following but fitting is way off. Could someone suggest a better/correct way to do this please?
%%%%a1=3.304*1.005%%%%
Eb_112T_a1=[1.7425 1.2007 0.7870 0.4811 0.2401 0.0541];
stress_112T_a1=[5.4876 5.5985 5.684 5.7465 5.7834 5.7958 ];
%%%%a2=3.304*1.01%%%%
Eb_112T_a2=[1.6581 1.1312 0.7297 0.4370 0.2080 0.0348];
stress_112T_a2=[5.4266 5.5390 5.627 5.6909 5.7304 5.7457];
%%%%a3=3.304*1.02%%%%
Eb_112T_a3=[1.4527 0.9538 0.5814 0.3186];
stress_112T_a3=[5.2062 5.318 5.4078 5.474];
Temp=[1831 3779.6 7.6773e3];
tau=[ stress_112T_a1 stress_112T_a2 stress_112T_a3];
Eb=[Eb_112T_a1 Eb_112T_a2 Eb_112T_a3];
dsid = [1*ones(length(stress_112T_a1),1); 2*ones(length(stress_112T_a2),1); 3*ones(length(stress_112T_a3),1)];
T = [tau' dsid];
b = nlinfit(T,Eb',@subfun,[35 5.9 2 8000])
H_pred1=b(1).*(1-(stress_112T_a1./b(2)).^b(3)).*(1-Temp(1)./b(4));
H_pred2=b(1).*(1-(stress_112T_a2./b(2)).^b(3)).*(1-Temp(2)./b(4));
H_pred3=b(1).*(1-(stress_112T_a3./b(2)).^b(3)).*(1-Temp(3)./b(4));
figure(1)
hold all
% plot(stress_112T_a0, Eb_112T_a0,'o')
% plot(stress_112T_a0, H_pred1)
plot(stress_112T_a1, Eb_112T_a1,'s')
plot(stress_112T_a1, H_pred1)
plot(stress_112T_a2, Eb_112T_a2,'d')
plot(stress_112T_a2, H_pred2)
plot(stress_112T_a3, Eb_112T_a3,'p')
plot(stress_112T_a3, H_pred3)
hold off
function yfit = subfun(params,T)
Temp=[1831 3779.6 7.6773e3]';
X = T(:,1);
dsid = T(:,2);
A0 = params(1);
A1 = params(2);
A2=params(3);
A3=params(4);
yfit = (A0.*(1-(X./A1)).^A2).*(1-Temp(dsid)./A3).*heaviside(1-(X./A1)).*heaviside(1-Temp(dsid)./A3);
end

Accepted Answer

Anik Faisal
Anik Faisal on 6 Mar 2019
I have figured out the issue with the fitting. The and are also functions of Temperatures and they need to be varied leaving and α only global fitting parametes.
clear; close all;
%%%%a0=3.304%%%%%
Eb_112T_a0=[1.7425 1.2007 0.7870 0.4811 0.2401 0.0541 0];
stress_112T_a0=[5.4876 5.5985 5.684 5.7465 5.7834 5.7958 5.806649218241550];
%%%%a1=3.304*1.005%%%%
Eb_112T_a1=[1.7425 1.2007 0.7870 0.4811 0.2401 0.0541];
stress_112T_a1=[5.4876 5.5985 5.684 5.7465 5.7834 5.7958 ];
%%%%a2=3.304*1.01%%%%
Eb_112T_a2=[1.6581 1.1312 0.7297 0.4370 0.2080 0.0348];
stress_112T_a2=[5.4266 5.5390 5.627 5.6909 5.7304 5.7457];
%%%%a3=3.304*1.02%%%%
Eb_112T_a3=[1.4527 0.9538 0.5814 0.3186];
stress_112T_a3=[5.2062 5.318 5.4078 5.474 ];
Temp=[1.2041e+03 2.4082e+03 4.8163e+03];
tau=[ stress_112T_a1 stress_112T_a2 stress_112T_a3];
Eb=[Eb_112T_a1 Eb_112T_a2 Eb_112T_a3];
dsid = [1*ones(length(stress_112T_a1),1); 2*ones(length(stress_112T_a2),1); 3*ones(length(stress_112T_a3),1)];
T = [tau' dsid];
%b = nlinfit(T,Eb',@subfun,[15 5.9 2 8000])
b=lsqcurvefit(@subfun,[2 5.7958 5.7457 5.4740 1 1.2041 2.4082 4.8163],T,Eb',[30 5.7958 5.7457 5.4740 .5 1.2041 2.4082 4.8163],[100 5.9 5.85 5.5 2.8 2 3.5 6])
H_pred1=b(1).*(1-(stress_112T_a1./b(2))).^b(5).*(1-Temp(1)./(b(6)*1e3));
H_pred2=b(1).*(1-(stress_112T_a2./b(3))).^b(5).*(1-Temp(2)./(b(7)*1e3));
H_pred3=b(1).*(1-(stress_112T_a3./b(4))).^b(5).*(1-Temp(3)./(b(8)*1e3));
figure(1)
hold all
% plot(stress_112T_a0, Eb_112T_a0,'o')
% plot(stress_112T_a0, H_pred0)
plot(stress_112T_a1, Eb_112T_a1,'s')
plot(stress_112T_a1, H_pred1)
plot(stress_112T_a2, Eb_112T_a2,'d')
plot(stress_112T_a2, H_pred2)
plot(stress_112T_a3, Eb_112T_a3,'p')
plot(stress_112T_a3, H_pred3)
hold off
function yfit = subfun(params,T)
temp=[1.2041e+03 2.4082e+03 4.8163e+03]';
X = T(:,1);
dsid = T(:,2);
A0 = params(1);
A1 = params(2:4)';
A2=params(5);
A3=params(6:8)';
yfit = (A0.*(1-(X./A1(dsid))).^A2).*(1-(temp(dsid)./(A3(dsid)*1e3))).*heaviside(1-(X./A1(dsid))).*heaviside(1-temp(dsid)./(A3(dsid)*1e3));
end

More Answers (2)

darova
darova on 5 Mar 2019
Dont understand why function fit cant find coeffiecient from script file. But cftool works fine
clc, clear
E0 = 540;
tau0 = 5.98;
alpha = 2.21;
Tm = 9846;
Temp = [1831 3779.6 7.6773e3];
Eb1 = [1.7425 1.2007 0.7870 0.4811 0.2401 0.0541];
tau1 =[5.4876 5.5985 5.684 5.7465 5.7834 5.7958 ];
Eb2 = [1.6581 1.1312 0.7297 0.4370 0.2080 0.0348];
tau2 = [5.4266 5.5390 5.627 5.6909 5.7304 5.7457];
Eb3 = [1.4527 0.9538 0.5814 0.3186];
tau3 = [5.2062 5.318 5.4078 5.474];
x = [tau1 tau2 tau3];
y = [tau1./tau1*Temp(1) tau2./tau2*Temp(2) tau3./tau3*Temp(3)];
z = [Eb1 Eb2 Eb3];
% ft = fittype( 'a.*(1-x./b).^c.*(1-y./d)', 'independent', {'x', 'y'}, 'dependent', 'z' );
% opts.StartPoint = [540 6 2 1e4];
% sf = fit( [x', y'], z', ft);
xx = linspace(min(x),max(x),20);
yy = linspace(min(y),max(y),20);
[X, Y] = meshgrid(xx,yy);
func = @(E0,tau0,alpha,Tm,x,y) E0.*(1-x./tau0).^alpha.*(1-y./Tm);
Z = func(E0,tau0,alpha,Tm,X,Y);
plot3(x,y,z,'.r')
hold on
surf(X,Y,Z)
% plot(sf,[x' y'], z')
hold off
xlabel('x')
ylabel('y')
Capture.PNG
  1 Comment
Anik Faisal
Anik Faisal on 5 Mar 2019
The a,b,c,d you get are the same values I get for b(1), b(2), b(3) and b(4) from my code. Are you suggesting only way to fit this data is to do surface plotting. I am looking for a 2D fitting. Thanks!

Sign in to comment.


Alex Sha
Alex Sha on 12 Oct 2019
How about the results follow:
Parameter Best Estimate
-------------------- -------------
b1 -1.42830819954452
b2 5.85107772359646
b3 -14.6752294095574
b4 9714.63276157523

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!