clc; % Example Cramer's rule % application of Kirchhoff's laws U1=5; U2=20; R1=20; R2=20; R3=40; display('Application of Kirchhoff''s laws') % matrix of the SLAE A=[1 1 -1; R1 0 R3; 0 R2 R3] % vector of right-hand side b = [0; U1; U2] % solution using Gauss elimination method and inverse matrix, respectively I= A\b I=inv(A)*b % solution of SLAE using Cramer's rule Ds=det(A) % check our solution of determinant Ds=-R1*R2-R2*R3-R3*R1 % Sarrus rule DI1=R3*U2-U1*R2-R3*U1 DI2=U1*R3-R1*U2-U2*R3 DI3=-R2*U1-U2*R1 I1=DI1/Ds I2=DI2/Ds I3=DI3/Ds % check the results (MATLAB solution - our solution) I-[I1;I2;I3] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Loop current method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % (R1+R3)*Ia + R3*Ib = U1 % R3*Ia + (R2+R3)*Ib = U2 display('Loop current method') A=[R1+R3, R3; R3, R2+R3]; b=[U1;U2]; IaIb=A\b; IR1=IaIb(1) IR2=IaIb(2) IR3=sum(IaIb) UR1=R1*IR1 UR2=R2*IR2 UR3=R3*IR3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Node voltage method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% display('Node voltage method') Ua=(R1*R3*U1+R1*R3*U2)/(R2*R3+R1*R3+R1*R2); IR1=(U1-Ua)/R1 IR2=(U2-Ua)/R2 IR3=Ua/R3 UR1=U1-Ua UR2=U2-Ua UR3=Ua %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Thevenin's theorem %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% display('Thevenin''s theorem') Ri=(R1*R2)/(R1+R2); Ix=(U2-U1)/(R1+R2); Ui=U1+R1*Ix; IR3=Ui/(Ri+R3) UR3=R3*IR3