function ss=YangLin(A,B)

N=200; % number of discretizations
X=linspace(A(1),A(4),N);

lowerA=mg(X,A(5:8),[0 A([9 9]) 0]);
upperA=mg(X,A(1:4));
lowerB=mg(X,B(5:8),[0 B([9 9]) 0]);
upperB=mg(X,B(1:4));

ss=0;
for i=1:N
    num=0;
    den=0;
    if upperA(i)>lowerA(i)
        for j=lowerA(i):(upperA(i)-lowerA(i))/100:upperA(i)
            if lowerA(i)<=j && j<=upperA(i)
                den=den+j;
                if lowerB(i)<=j && j<=upperB(i)
                    num=num+j;
                end
            end
        end
        if den>0
            ss=ss+num/den;
        end
    elseif lowerA(i)>=lowerB(i) && upperA(i)<=upperB(i) 
        ss=ss+1;
    end
end
ss=ss/N;

