export const MODEL_VERSION='1.0.0',DEFAULTS=Object.freeze({Rn:200,R4:9720,frequency:1000,Rx:194.4,Cx:.1/.972}); export function validateParameters(p){for(const[k,a,b]of[['Rn',10,1000],['R4',5000,20000],['frequency',100,10000],['Rx',100,300],['Cx',.05,.2]])if(!Number.isFinite(p[k])||p[k]b)throw new RangeError(k);return{...p};} export function response(p){validateParameters(p);const w=2*Math.PI*p.frequency,x=-1/(w*p.Cx*1e-6),n=-1/(w*.1e-6),a=p.Rx+p.Rn,b=x+n,den=a*a+b*b,real=(p.Rn*a+n*b)/den-10000/(p.R4+10000),imag=(n*a-p.Rn*b)/den;return{Rn:p.Rn,R4:p.R4,real,imag,magnitude:Math.hypot(real,imag),inferredR:p.R4/10000*p.Rn,inferredC:10000/p.R4*.1,loss:w*p.Rn*.1e-6};} export function plots(p){const rns=Array.from({length:201},(_,i)=>10+990*i/200),r4s=Array.from({length:201},(_,i)=>5000+15000*i/200);return[{caption:'调节标准电阻时桥压的复平面轨迹',xLabel:'Re(UG / E)',yLabel:'Im(UG / E)',curves:[{points:rns.map(Rn=>{const r=response({...p,Rn});return[r.real,r.imag];})}],selected:[response(p).real,response(p).imag]},{caption:'比率臂调节时桥压实部与虚部',xLabel:'比率臂 R4 / Ω',yLabel:'桥压分量 / E',legend:'实线:实部 虚线:虚部',curves:['real','imag'].map(key=>({points:r4s.map(R4=>[R4,response({...p,R4})[key]])}))}];} export function analyzeRecords(rows,p){const s=rows.filter(r=>['frequency','Rx','Cx'].every(k=>r.parameters[k]===p[k]));if(!s.length)return'调节两个独立参数,使实部、虚部同时趋于零后记录候选损耗与电容。';const best=s.reduce((a,b)=>a.readings.magnitude