%% IT38 feladat megoldása
% Megoldas csomoponti potencialok modszerevel 
% ismeretlenek : ia ib ic id ua ub uc ud U
% gerjesztes :  I0
% keresett mennyiseg : U
syms ia ib ic id ua ub uc ud m n I0 U R
eq1 = ia == -I0;
eq2 = ia + ic + ib == 0;
eq3 = -ic + id + ud/R == 0;
eq4 = -U - ua +ub ==0;
eq5 = ua == n*ub;
eq6 = ib == -n*ia;
eq7 = uc == m*ud;
eq8 = id == -m*ic;
eq9 = ub-uc-ud == 0;

sol = solve([eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9],[ua,ub,ia,ib,uc,ud,ic,id,U]);
% sol.ua
pretty(sol.U/I0)
pretty(collect(sol.U/I0))
pretty(simplify(sol.U/I0))

%% Masik megoldas hurokaramokkal 
% Talan nem ez az igazan jo, de akkor is...
% ismeretlenek : ua, ub, uc, ud, ia, ib, ic, id, j1, j2, j3, UAB
% gerjesztes : I0
% keresett mennyiseg : UAB
clear all
syms ua ub uc ud ia ib ic id j1 j2 j3 UAB n m R I0
eq1 = ua == n*ub;
eq2 = uc == m*ud;
eq3 = ib == -n*ia;
eq4 = id == -m*ic;
eq5 = -UAB - ua + ub == 0;
eq6 = uc + ud - ub ==0;
eq7 = j3*R - ud == 0;
eq8 = ia == -j1;
eq9 = ib == j1 -j2;
eq10= ic == j2;
eq11= id == j2 - j3;
eq12= j1 == I0;
 
sol = solve( [eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10,eq11,eq12], ...
  [ua,ub,ia,ib,uc,ud,ic,id,UAB,j1,j2,j3]);

pretty( simplify(sol.UAB))