% The equation using Sw and Sz is     Sz = (S1 + S2) - S1*S2 (1/Sw)
% and that using     Sn and Sw is     Sw = (S1 + S2) - S1*S2 (1/Sn)


sa = 4
sb = 5.5;

sw = 4.662
sz= 5.005
szp1 = 5.310
sn = 4.275

% clear;
syms z w a b n
% 
% solve('z = a+b-a*b/w','w=a+b-a*b/n','a','b')

% abbreviate sw = w, sz = z, szp1 = z, sn = n; a = S1, b = S2;

syms a1 a2 b1 b2 

a1 = w*(z-1/2/(n-w)*(w*n-z*w+(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2)))/(w-1/2/(n-w)*(w*n-z*w+(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2)))
a2 = w*(z-1/2/(n-w)*(w*n-z*w-(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2)))/(w-1/2/(n-w)*(w*n-z*w-(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2)))
 
b1 = 1/2/(n-w)*(w*n-z*w+(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2));
b2 = 1/2/(n-w)*(w*n-z*w-(-3*w^2*n^2-6*w^2*n*z+z^2*w^2+4*w*n^2*z+4*w^3*n)^(1/2));
 

% from gofs:
w = 4.662; z = 5.005; n = 4.275;
% % from ls-g*(S):
% w = 4.762;
% z = 5.074;
% n = 4.411;
% 
% %from c(s) with regularization:
w = 4.752;
z = 4.873;
n = 4.631;
% 
% %from c(s) very sharp, bimodal :
% w = 4.750;
% z = 4.869;
% n = 4.632;
% 


% this is first solution
eval(a1)
eval(b1)

% this is second solution
eval(a2)
eval(b2)



