vectorization - Converting mathematical expressions to Matlab scripts -


i have equations , want code them in matlab. these parts of equality constraints optimization problem. it's gams script , mathematical equation known me. these terms follows:

enter image description here

gams: p1_bal(ib)  ..      (pgn1(ib)-pdn1(ib)) =e= v1(ib)*sum(ib1, ybus1_m(ib,ib1)*v1(ib1)*cos(ybus1_a(ib,ib1)+a1(ib1)-a1(ib))); q1_bal(ib)  ..      (qgn1(ib)-qdn1(ib)) =e= -v1(ib)*sum(ib1, ybus1_m(ib,ib1)*v1(ib1)*sin(ybus1_a(ib,ib1)+a1(ib1)-a1(ib))); 

so have tried write it's matlab scrip based on above, not sure if true. please check these matlab scrip , tell me if in accordance mathematical or gams scripts.

p_bal  =  -(pgn-pdn)+v_mt.*((ybus_m.*cos(delta)*v_mt));  q_bal  =   -(qgn-qdn)+v_mt.*((ybus_m.*sin(delta))*v_mt);  

where pgn,pdn,qgn,qdn,v_mt (n x 1) vectors ybus_m , delta (n x n) matrices. delta defined :

delta =bsxfun(@minus,v_at(:),v_at(:).')-ybus_a;    %v_at(:)=d{n},v_at(:)'=d{h},ybus_a=tet{n,h} 


Comments