blob: 9298b47b5fdc4df5d2b7c5f8f547c2ef7c03d175 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
//Current through 2 ohm resistor given a current source
clc;
clear;
Is=2; // Current Source
//Resistors connected directly to the current source
Rs1=0.5;
Rs2=0.5;
//Resistors in various branches starting from the top
R1=1;
R2=1;
R3=2;
//Conversion to voltage sources
V1=Rs1*Is; // Voltage across first half of the branch
V2=Rs2*Is; // Voltage across second half of the branch
// Voltage sources in the circuit
V3=1;
V4=2;
//Characteristic Equations
//2.5i1-1i2 = 2
//-1i1+3.5i2 = 2
R=[2.5 -1; -1 3.5]; // Resistor Vector
V=[(V1+V3);(V2+V4-V3)]; // Voltage Vector
I=inv(R)*V; // Current Vector
i1=I(1);
i2=I(2);
printf('The Current through the 2 ohm resistor = %g A\n',i2)
|