MATLAB: How to fit multiple curves with same fitting parameters

curve fittingMATLABnonlinearregression

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

Best Answer

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