% MICROCRE teaching simulation: Two-component absorbance spectrum % NOT EXECUTED IN MATLAB/Octave in the authoring environment. % Python/SciPy counterpart has been run; see validation-report.json. % Standalone MATLAB R2016b+ script (local functions); no extra toolbox required. % Edit p below, run this file, inspect outputs and assumptions before use. % Formula: A(λ)=lΣc_i ε_i(λ);ε₁,max=15000、ε₂,max=10000 L/(mol·cm);T=10⁻ᴬ % Assumption: 稀溶液、均匀光程、组分独立吸收;谱带标准差固定25/35 nm。 % Assumption: 300—800 nm以0.5 nm采样;浓度从µmol/L乘10⁻⁶。 % Limitation: 无散射、杂散光、化学平衡、仪器带宽与饱和效应。 % Limitation: 不是真实化合物谱库,也不构成浓度定量校准。 % Source: https://goldbook.iupac.org/terms/view/B00626 % This is not product performance, calibration, or compliance evidence. clear; close all; clc; p.concentration1 = 20; % 组分1浓度 [µmol/L] p.concentration2 = 10; % 组分2浓度 [µmol/L] p.path = 1; % 光程 [cm] p.center1 = 450; % 谱带1中心 [nm] p.center2 = 550; % 谱带2中心 [nm] assert(isfinite(p.concentration1) && p.concentration1>=0 && p.concentration1<=1000, 'Invalid concentration1'); assert(isfinite(p.concentration2) && p.concentration2>=0 && p.concentration2<=1000, 'Invalid concentration2'); assert(isfinite(p.path) && p.path>=0.001 && p.path<=10, 'Invalid path'); assert(isfinite(p.center1) && p.center1>=350 && p.center1<=700, 'Invalid center1'); assert(isfinite(p.center2) && p.center2>=350 && p.center2<=700, 'Invalid center2'); wavelength=linspace(300,800,1001); a1=p.path*p.concentration1*1e-6*15000*exp(-0.5*((wavelength-p.center1)/25).^2); a2=p.path*p.concentration2*1e-6*10000*exp(-0.5*((wavelength-p.center2)/35).^2); total=a1+a2; [peak,idx]=max(total); lines=[s('Component 1',wavelength,a1,'nm','absorbance'),s('Component 2',wavelength,a2,'nm','absorbance'),s('Additive absorbance',wavelength,total,'nm','absorbance')]; out=struct('peak_absorbance',peak,'peak_wavelength',wavelength(idx),'minimum_transmittance',10^(-peak)); outdir=fullfile(pwd,'spectral-absorbance_results'); if ~exist(outdir,'dir'),mkdir(outdir);end fid=fopen(fullfile(outdir,'spectral-absorbance.csv'),'w'); assert(fid>=0,'Cannot open CSV'); fprintf(fid,'series,x,y,x_unit,y_unit\n'); for j=1:numel(lines) for k=1:numel(lines(j).x) fprintf(fid,'"%s",%.17g,%.17g,"%s","%s"\n',lines(j).name,lines(j).x(k),lines(j).y(k),lines(j).xu,lines(j).yu); end end fclose(fid); fig=figure('Color','w');hold on; for j=1:numel(lines) if lines(j).plot,plot(lines(j).x,lines(j).y,'LineWidth',1.5,'DisplayName',lines(j).name);end end grid on;legend('show','Location','best');xlabel(lines(1).xu);ylabel(lines(1).yu); title('Two-component absorbance spectrum','Interpreter','none'); print(fig,fullfile(outdir,'spectral-absorbance.png'),'-dpng','-r160'); fid=fopen(fullfile(outdir,'spectral-absorbance-summary.json'),'w');fprintf(fid,'%s',jsonencode(struct('inputs',p,'outputs',out,'notice','Teaching model; not product validation.')));fclose(fid); disp(out); function a=s(name,x,y,xu,yu) a=struct('name',name,'x',x,'y',y,'xu',xu,'yu',yu,'plot',true); end function q=qlinear(values,p) v=sort(values); pos=p*(numel(v)-1); k=floor(pos)+1; f=pos-floor(pos); if k==numel(v),q=v(k);else,q=v(k)*(1-f)+v(k+1)*f;end end