
load('Saha_partition_functions.mat')



%pull apart:
p=[];
p(1)=1.5074e-21;
p(2)=-1.2955e-16;
p(3)=4.2398e-12;
p(4)=-6.2329e-08;
p(5)=3.1937e-04;
p(6)= 1.0658;
T_plasma = T;
%T_plasma = T(1):500:T(length(T));
T_plasma_fine = T(1):1:T(length(T));
PartitionSumFeI=[];
PartitionSumFeII=[];
PartitionSumFeI= interp1(T, FeI, T_plasma); 
PartitionSumFeII= interp1(T, FeII, T_plasma);
%CathModSahakonstant = 2*PartitionSumFeII./PartitionSumFeI/(5.5585*10^-15*1)^(3/2) .* CathModTplasmaLocal.^(3/2).*exp(-CathModEion/CathModkB./CathModTplasmaLocal);
%CathModnis = (sqrt(4*CathModrhos/CathModmi/CathModSahakonstant+1)-1)/2*CathModSahakonstant;
%p=polyfit(T_plasma, PartitionSumFeII./PartitionSumFeI, 4)

p=polyfit(T_plasma, PartitionSumFeII./PartitionSumFeI, 5)
f1=polyval(p, T_plasma_fine);
plot(T_plasma, PartitionSumFeII./PartitionSumFeI, 'o', 'linewidth', 2)
hold on
plot(T_plasma_fine, f1, 'linewidth', 2)
hold off

xlim([2500 25500])
ylabel('Z_{Fe+}/Z_{Fe}', 'FontSize', 12)
xlabel('T_{Plasma,local} [K]', 'FontSize', 12)
legend({'Data from NIST ASD', 'P_{FractionPartitionSum}'}, 'FontSize', 12)
grid on

ax = gca;
ax.FontSize = 14