% MassCal.m

pkg load symbolic
%calculate solution to reciprocity calibration with syms

syms Zm Ze ToSq ZinL1 ZinL2 ZinL3 ZL1 ZL2 ZL3

ZinL1_Alg = Ze + ToSq/(ZL1 + Zm);
ZinL2_Alg = Ze + ToSq/(ZL2 + Zm);

%what if Ze is known?
ToSq_Zm = simplify(solve(ZinL1_Alg==ZinL1,ToSq));
ZinL2_Alg2 = simplify(subs(ZinL2_Alg,ToSq,ToSq_Zm));
Zm_sol = simplify(solve(ZinL2_Alg2==ZinL2,Zm));
ToSq_sol = simplify(subs(ToSq_Zm,Zm,Zm_sol));

[nToSq_sol,dToSq_sol] = numden(ToSq_sol);
ToSq_sol = factor(nToSq_sol)/factor(dToSq_sol);
[nZm_sol,dZm_sol] = numden(Zm_sol);
Zm_sol = factor(nZm_sol)/factor(dZm_sol);
