function [ wout ] = wopt( Pij,Hi,Hj,R1x,Rij )
val=1000000;
Pj=R1x;
for j=1:1:99;
    w=.01*j;
    P1=(1/w)*Pij;
    P2=(1/(1-w))*Hj*Pj*Hj'+Rij;
    K=P1*Hi'*inv(Hi*P1*Hi'+P2);
    Pijplus=(eye(2)-K*Hi)*P1;
    valc=trace(Pijplus);
    if valc<val
        val=valc;
        wout=w;
    end
end
        