# Mesh Circuit 4by4

```clear
clc
mode='select the mode: (1) for preset values (2) for user entering values\n';
fprintf(mode);
x=input('');
if(x==1)
R1 = 2700;
R2 = 8000;
R3 = 2200;
R4 = 6800;
R5 = 1000;
R6 = 1000;
R7 = 2700;
R8 = 6600;
R9 = 3300;
E1 = 1.5;
E2 = 1.5;
E3 = 1.5;
E4 = 1.5;

R = [(R1+R2+R5) -R2 R5 0;-R2 (R2+R3+R4+R6) 0 R6;R5 0 (R7+R8+R5) -R8;0 R6 -R8 (R8+R6+R9)];
E = [(E1-E2) (E2-E3) -E4 E4]';
I = inv(R)*E;

VR1= I(1) *R1;
VR2= (I(1) - I(2))*R2;
VR3= I(2)*R3;
VR4= I(2)*R4;
VR5= I(3)*R5;
VR6= I(2)-I(4) *R6;
VR7= I(3)*R7;
VR8= I(4)*R8;
VR9= I(4)*R9;

PR1= (VR1^2)/R1;
PR2= (VR2^2)/R2;
PR3= (VR3^2)/R3;
PR4= (VR4^2)/R4;
PR5= (VR5^2)/R5;
PR6= (VR6^2)/R6;
PR7= (VR7^2)/R7;
PR8= (VR8^2)/R8;
PR9= (VR9^2)/R9;

fprintf('iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi\n');
fprintf('Current Throught loop1 = %5.10f Amps           iT\n',I(1));
fprintf('Current Throught loop2 = %5.10f Amps           iT\n',I(2));
fprintf('Current Throught loop3 = %5.10f Amps           iT\n',I(3));
fprintf('Current Throught loop4 = %5.10f Amps           iT\n',I(4));
fprintf('iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi\n');

fprintf('vVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvV\n');
fprintf('Voltage across R1 = %5.10f volts               vV\n',VR1);
fprintf('Voltage across R2 = %5.10f volts               vV\n',VR2);
fprintf('Voltage across R3 = %5.10f volts               vV\n',VR3);
fprintf('Voltage across R4 = %5.10f volts               vV\n',VR4);
fprintf('Voltage across R5 = %5.10f volts               vV\n',VR5);
fprintf('Voltage across R6 = %5.10f volts               vV\n',VR6);
fprintf('Voltage across R7 = %5.10f volts               vV\n',VR7);
fprintf('Voltage across R8 = %5.10f volts               vV\n',VR8);
fprintf('Voltage across R9 = %5.10f volts               vV\n',VR9);
fprintf('vVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvV\n');

fprintf('pPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpP\n');
fprintf('Power Dissipated by R1 = %5.10f waths          pP\n',PR1);
fprintf('Power Dissipated by R2 = %5.10f waths          pP\n',PR2);
fprintf('Power Dissipated by R3 = %5.10f waths          pP\n',PR3);
fprintf('Power Dissipated by R4 = %5.10f waths          pP\n',PR4);
fprintf('Power Dissipated by R5 = %5.10f waths          pP\n',PR5);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR6);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR7);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR8);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR9);
fprintf('pPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpP\n');

else(x==2);
R1 = input('Enter the value of R1 in Ohms ');
R2 = input('Enter the value of R2 in Ohms ');
R3 = input('Enter the value of R3 in Ohms ');
R4 = input('Enter the value of R4 in Ohms ');
R5 = input('Enter the value of R5 in Ohms ');
R6 = input('Enter the value of R6 in Ohms ');
R7 = input('Enter the value of R7 in Ohms ');
R8 = input('Enter the value of R8 in Ohms ');
R9 = input('Enter the value of R9 in Ohms ');
E1 = input('Enter the value of the voltage source in Volts ');
E2 = input('Enter the value of the voltage source in Volts ');
E3 = input('Enter the value of the voltage source in Volts ');
E4 = input('Enter the value of the voltage source in Volts ');

R = [(R1+R2+R5) -R2 R5 0;-R2 (R2+R3+R4+R6) 0 R6;R5 0 (R7+R8+R5) -R8;0 R6 -R8 (R8+R6+R9)];
E = [(E1-E2) (E2-E3) -E4 E4]';
I = inv(R)*E;

VR1= I(1) *R1;
VR2= (I(1) - I(2))*R2;
VR3= I(2)*R3;
VR4= I(2)*R4;
VR5= I(3)*R5;
VR6= I(2)-I(4) *R6;
VR7= I(3)*R7;
VR8= I(4)*R8;
VR9= I(4)*R9;

PR1= (VR1^2)/R1;
PR2= (VR2^2)/R2;
PR3= (VR3^2)/R3;
PR4= (VR4^2)/R4;
PR5= (VR5^2)/R5;
PR6= (VR6^2)/R6;
PR7= (VR7^2)/R7;
PR8= (VR8^2)/R8;
PR9= (VR9^2)/R9;

fprintf('iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi\n');
fprintf('Current Throught loop1 = %5.10f Amps           iT\n',I(1));
fprintf('Current Throught loop2 = %5.10f Amps           iT\n',I(2));
fprintf('Current Throught loop3 = %5.10f Amps           iT\n',I(3));
fprintf('Current Throught loop4 = %5.10f Amps           iT\n',I(4));
fprintf('iIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi\n');

fprintf('vVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvV\n');
fprintf('Voltage across R1 = %5.10f volts               vV\n',VR1);
fprintf('Voltage across R2 = %5.10f volts               vV\n',VR2);
fprintf('Voltage across R3 = %5.10f volts               vV\n',VR3);
fprintf('Voltage across R4 = %5.10f volts               vV\n',VR4);
fprintf('Voltage across R5 = %5.10f volts               vV\n',VR5);
fprintf('Voltage across R6 = %5.10f volts               vV\n',VR6);
fprintf('Voltage across R7 = %5.10f volts               vV\n',VR7);
fprintf('Voltage across R8 = %5.10f volts               vV\n',VR8);
fprintf('Voltage across R9 = %5.10f volts               vV\n',VR9);
fprintf('vVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvVvV\n');

fprintf('pPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpP\n');
fprintf('Power Dissipated by R1 = %5.10f waths          pP\n',PR1);
fprintf('Power Dissipated by R2 = %5.10f waths          pP\n',PR2);
fprintf('Power Dissipated by R3 = %5.10f waths          pP\n',PR3);
fprintf('Power Dissipated by R4 = %5.10f waths          pP\n',PR4);
fprintf('Power Dissipated by R5 = %5.10f waths          pP\n',PR5);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR6);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR7);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR8);
fprintf('Power Dissipated by R6 = %5.10f waths          pP\n',PR9);
fprintf('pPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpPpP\n');

end```

Result