% MOC BILANCA A=[1,0,0,1,0;-1,1,1,0,0;0,-1,0,0,1;20,0,10,-1,0;0,5,-10,0,40] b = [ -2 ; 0 ;2 ;10 ;0] x=A\b AV=[1+1/20,-1/20,0;-1/20,1/10+1/20+1/5,-1/5;0,-1/5,1/5+1/40] bV=[-2+10;0;2] V=AV\bV Pg=10*(-x(4))+2*(V(3)-V(1)) R=[20;5;10;1;40] Pb=sum(x.^2.*R)