% Circuit parameters r = round(100*rand(8,1)) v0 = round(100*randn) % Kirchoff‘s voltage law A = [1 -1 0 0 0 1 -1 0 -1 0 1 0 0 -1 0 0 0 0 -1 1 1 0 0 0 0 0 0 -1 -1 0 0 1] % Symbolically symr = sym(‘[r12 r13 r14 r23 r34 r25 r35 r45]‘); R = A‘*diag(symr)*A % Numerically R = A‘*diag(r)*A; b = [0 0 0 v0]‘ i = R\[0 0 0 v0]‘ % Kirchoff‘s current law B = [1 -1 0 0 1 0 -1 0 1 0 0 -1 0 1 -1 0 0 0 1 -1 0 1 0 0 0 0 1 0 0 0 0 1] % Symbolically symg = sym(‘[g12 g13 g14 g23 g34 g25 g35 g45]‘); G = B‘*diag(symg)*B % Numerically g = 1./r; g35 = g(7); G = B‘*diag(g)*B c = [0 0 g35*v0 0]‘ v = G\c % Check consistency d = [0 0 0 0 0 0 v0 0]‘; [(B*v-d)./(A*i) r]
以上matlab程序对电路的特性进行了模拟、仿真。
其中电路图的形状是这样的:
其中电流的方向均为顺时针方向。
根据电路中给出的这些参量,结合KCL(Kirchoff‘s current law),KVL(Kirchoff‘s voltage law)来分析之。
X = randn returns a random scalar drawn from the standard normal distribution.
sym Create the symbolic variables
X = rand returns a single uniformly distributed random number in the interval (0,1).
X = rand(n) returns an n-by-n matrix of random numbers
其中下面这条语句返回的是一个符号变量构成的行向量。
>> sym(‘[r12 r13 r14 r23 r34 r25 r35 r45]‘)
ans =
[ r12, r13, r14, r23, r34, r25, r35, r45]
进一步分析,将其置于矩阵的对角线位置上,得到的矩阵的形状是这样的:
>> symr = sym(‘[r12 r13 r14 r23 r34 r25 r35 r45]‘);
>> diag(symr)
ans =
[ r12, 0, 0, 0, 0, 0, 0, 0]
[ 0, r13, 0, 0, 0, 0, 0, 0]
[ 0, 0, r14, 0, 0, 0, 0, 0]
[ 0, 0, 0, r23, 0, 0, 0, 0]
[ 0, 0, 0, 0, r34, 0, 0, 0]
[ 0, 0, 0, 0, 0, r25, 0, 0]
[ 0, 0, 0, 0, 0, 0, r35, 0]
[ 0, 0, 0, 0, 0, 0, 0, r45]
>> A‘*diag(symr)*A
ans =
[ r12 + r14 + r25 + r45, -r12, -r14, -r45]
[ -r12, r12 + r13 + r23, -r13, 0]
[ -r14, -r13, r13 + r14 + r34, -r34]
[ -r45, 0, -r34, r34 + r35 + r45]
求得的是电阻矩阵。