2013 XXIV International Conference on Information, Communication and Automation Technologies (ICAT) October 30 – November 01, 2013, Sarajevo, Bosnia and Herzegovina Novel Matrix-based Improvement of Nodal Analysis for Circuits with Singularities Željko Jurić Harun Šiljak Department of Automatic Control & Electronics Faculty of Electrical Engineering, University of Sarajevo Sarajevo, Bosnia & Herzegovina zjuric@utic.net.ba Department of Electrical & Electronics Engineering Burch International University Sarajevo, Bosnia & Herzegovina hsiljak@ibu.edu.ba Abstract — This paper presents an alternative to existing techniques based on Nodal Analysis designed specifically to suit implementation in matrix-oriented programming languages, keeping the simplicity of original Nodal Analysis and bringing improvements to make virtually all circuit topologies solvable through it, dealing with potential singularities, hence the name Singular Nodal Analysis (SNA). Two variants of this novel algorithm are described. Their validity is proven and their applicability is shown through two practical examples. Keywords — electrical circuits; nodal analysis; singular; ideal voltage source; coupled inductors I. INTRODUCTION Node potential method, also known as NA (Nodal Analysis) is probably one of the most used methods for linear electrical circuits analysis [1]. Beside the fact that this method in general leads to smaller systems of equations than other methods, its additional advantage is the fact that all input data for the method may be simply read directly from the circuit description (schematic or other), as well as the fact that the whole algorithm can be expressed in basic matrix operations such as multiplication, matrix inverse etc. in a very compact manner [2]. All of this enables extremely simple and compact implementation in programming languages with matrix calculations support, such as MATLAB, or the programmable calculators with built-in matrix calculations, such as advanced models of manufacturers like Texas Instruments or Hewlett Packard. Unlike NA, most other methods, such as MA (Mesh Analysis) or LCA (Loop Current Analysis) ask for a certain topological analysis of the circuit, e. g. finding one of the trees in a graph representing the circuit [3], [4]. Although such analysis may be relatively easily performed using e. g. BFS search, it can't be reduced to matrix operations and must be implemented by manipulating single elements of corresponding matrices. That makes their implementation more complicated, larger and slower in matrix-oriented programming languages, since such languages are not particularly optimized or sometimes even flexible enough to conduct operations on particular matrix elements. Moreover, such implementations always ask for explicitly coded loops, which are usually inefficient in matrixoriented languages (especially on programmable calculators). With all the advantages of NA method listed, its main shortcoming is still severe – failing in cases when the branch 978-1-4799-0431-0/13/$31.00 ©2013 IEEE impedance matrix is singular [5]. This always happens in case when there are branches with zero impedance, e. g. branches in short-circuit (either directly, either in a sophisticated case like a serial LC resonant combination), or branches with ideal voltage sources. However, branch impedance matrix can become singular in certain not-so-obvious cases as well. For instance, this matrix may become singular if there are two purely inductive branches with perfect inductive coupling (i. e. with coupling coefficient k = 1). If there is a whole group of inductively coupled branches in the consideration, branch impedance matrix may become singular even when the coupling is not perfect. For instance, if there are three purely inductive branches, P, Q and R, the impedance matrix will be singular if the coupling coefficients for these branches satisfy the equality kPQ2 + kQR2 + kPR2 = 1 + 2 kPQ kQR kPR (1) (e. g. kPQ = kQR = 0.8, kPR = 0.28). Finally, some configurations of circuits with dependent voltage or current sources also may lead to a singular branch impedance matrix. All cases listed above cannot be solved using NA directly. In addition, NA may be numerically unstable if values of impedance of certain branches are significantly lower than impedances of most other branches in the circuit (e. g. branches containing nearly ideal voltage sources, or very small resistances such as resistance of a conducting diode). It is a fact that for all cases listed above a relatively simple transformation can be conducted, taking the original circuit to a more or less equivalent circuit such that NA is applicable. For instance, short-circuited branches are trivially removed by merging the short-circuited nodes into one node. Still, the currents through those branches need to be determined indirectly using Kirchhoff's current law. Besides that, merging nodes can lead to unexpected situations as well. For instance, if an inductively coupled inductor is bridged by a short circuit, its current will not be zero because of the inductive coupling action. However, if we merge the short-circuited nodes into one node, after such merge the branch with inductively coupled inductor will start and end at the same node, which is a situation that NA cannot handle. Although the current through such branch can be easily determined indirectly, this makes it a special case which has to be additionally programmed if we want a program that deals successfully with all cases. Furthermore, ideal voltage sources can be treated by introducing supernodes, but it disrupts the simplicity of method's matrix description. Alternatively, various equivalent transformations can be applied to eliminate ideal voltage sources, but such procedures require extra programming as well. Besides that, the currents through ideal voltage sources at the end have to be calculated indirectly as well, after finding all other currents. Finally, inductively coupled branches (including those “causing problems”) can in principle be removed using T or Π equivalent schemes, which of course means extra programming again. Additional problem lies in the fact that all of these extra programming tasks cannot be expressed using matrix operations, but again require individual matrix elements' manipulation. Someone can object that such problems are easy to overcome by putting a very small resistance in all problematic branches, e. g. branches with ideal voltage sources. Although such approach is sometimes used, it is not a good idea anyway, because too small values of such resistance may cause severe numerical instabilities and, from the other side, greater values can significantly disturb the accuracy of the calculated result. Taking into account all the shortcomings listed, a modified method of node potentials has been developed, called MNA (Modified Nodal Analysis) [6], dealing with most of the problems appearing in practice. Although it is a very successful method, used as a basis for most software packages available for electrical circuits solving (SPICE is the most famous example), it is a fact that it is a somewhat confusing method mixing different variables (e. g. voltages and currents) in same equations, and it is not easy to represent it in a compact matrix form suitable for matrix-calculation based implementation. Because of this, it is hard to use matrix calculation support in matrix-oriented programming languages for its implementation. There is also an alternative approach known as STA (Sparse Tableau Approach) [7], which has the equal power as MNA. Although it is more matrix-oriented than MNA, it produces quite large but sparse matrices, which are not so suitable for the manipulation using standard matrix algorithms. Using the special algorithms for working with sparse matrices, STA may be more efficient than MNA [8]. However, STA is again not a well-suitable solution for the matrix-oriented programming languages. Due to the prevailing belief that the circuit analysis problem is completely and well solved by either MNA or STA, there was almost no new works in this area after the publication of MNA and STA. Really, these methods do their job quite well. However, we already said that they do not allow the compact implementation in matrix-oriented programming languages. Therefore, they are also not suitable for the implementation in the programmable calculators with the built-in support for the matrix calculations. The goal of this paper is to offer a simple alternative for both MNA and STA methods. The method proposed here, named SNA (Singular Nodal Analysis), deals without problems with all described cases of NA method failure. However, unlike MNA, this method can be easily implemented using only basic matrix operations (like NA), leading to simple and compact implementations in matrix-oriented languages. Also, it produces much smaller matrices than STA. It should be noted that the focus of SNA algorithm is on simplicity and compactness of the implementation, not on performance, since MNA is more efficient than SNA from the performance aspect (although it is easily shown that both SNA and MNA have the same order of complexity, differing just by a constant factor). Basically, SNA method is primarily developed for short and simple implementation on the programmable calculators and the matrix-oriented languages like MATLAB. Such a method has a pedagogical aspect as well, thereby following a trend of similar NA enhancements appearing in research [9]. Section II of this paper gives an overview of SNA method without a proof of its validity, and the proof is given in Section III. Finally, Section IV illustrates the presented theory with two specific examples. II. SNA ALGORITHM Before presenting the SNA algorithm itself, the classical NA algorithm will be briefly presented in order to introduce a reference for comparison and terminology usage [1]. For a given circuit with Nb branches, Nc ideal current sources and Nn+1 nodes, where one node (node 0) is arbitrarily chosen as a reference node, we assume that the input data is as follows: • Branch and nodes incidence matrix A with dimensions Nn × Nb where (A)i, j = –1 if branch i leaves node j, (A)i, j = 1 if branch i enters the node j and (A)i, j = 0 otherwise. • Impedance matrix Zb of the form Nb × Nb in which (Zb)i, i is i-th branch impedance, while (Zb)i, j, i ≠ j is the mutual impedance between i-th and j-th branch. If i-th and j-th branch are inductively coupled, then (Zb)i, j and (Zb)j, i contain inductive mutual impendance between those two branches. If a dependent voltage source exists in j-th branch, controlled with current in i-th branch, (Zb)i, j is increased by the amount of transimpedance of that dependent source. In all other cases, (Zb)i, j or equivalently (Zb)j, i with i ≠ j is equal to zero. • Vector Eb with Nb components (i. e. matrix with dimensions Nb × 1) where (Eb)i is the electromotive force of i-th branch (taking care of branch orientation). • Ideal current sources and nodes incidence matrix Ac with dimensions Nn × Nc where (Ac)i, j = –1 if i-th current source leaves the node j, (Ac)i, j = 1 if i-th current source enters the node j and (Ac)i, j = 0 otherwise. • Vector Jc with Nc components (i. e. matrix having the form Nc × 1) where (Jc)i is the current of i-th current source. As the result of the algorithm execution, the following output data are generated: • Vector Vn of node potentials with Nn components, where (Vn)i is the potential of i-th node with respect to the chosen reference node. • Vector Jb of branch currents with Nb components, where (Jb)i is the current through i-th branch (taking care of branch orientation). In this notation, classical NA is expressed in a very simple pseudo-code, which is shown in Fig. 1. Input: A, Zb, Eb, Ac, Jc Output: Vn, Jb Yb ← Zb–1 Vn ← (A Yb AT )–1 (A Yb Eb + Ac Jc) Jb ← Yb (Eb – AT Vn) Fig. 1. Pseudo-code of standard NA. Algorithm description makes it clear that it fails if the matrix Zb is singular, which includes cases described in the introductory section (possibility that the matrix A Yb AT is singular will be discussed later). In a case when the circuit does not contain ideal current sources, the term Ac Jc should simply be omitted (similar remark holds for all algorithms that follow). For the sake of generality, in the following discussion it will be assumed that such sources exist in the circuit as well. This pseudo-code is very simply translated into a MATLAB program shown in Fig. 2. function [Jb,Vn]=NA(A,Zb,Eb,Ac,Jc) Yb=inv(Zb); Vn=(A*Yb*A')\(A*Yb*Eb+Ac*Jc); Jb=Yb*(Eb-A'*Vn); Fig. 2. MATLAB implementation of standard NA. Here, the multiplication of inverse matrix with another matrix is replaced with MATLAB’s matrix left division operator (X–1Y = X \ Y), which is faster and more accurate. NA algorithm as presented here is only suitable if the only possible dependent sources in the circuit are the current controlled voltage sources, because only such sources can be directly represented in the matrix Zb. It is possible to extend the method for other types of dependent sources by introducing new matrices, but due to lack of space, such generalizations will not be considered in this paper. It should also be noted that the node admittance matrix Yn = A Yb AT and the node current vector Jn = A Yb Eb + Ac Jc can be read directly from the electrical circuit (without explicitly making matrices like A, etc.) if the circuit does not contain inductive couplings and dependent voltage sources. This is another reason why NA method has gained wide popularity. Now, we may proceed to the description of the proposed SNA (Singular Nodal Analysis) algorithm. This algorithm comes in two variants: CSNA (Conservative SNA) and SSNA (Selective SNA). This section only presents the algorithms, while the next one deals with the proof of their validity. The CSNA algorithm is significantly slower than SSNA algorithm, since it works with larger matrices. Its advantage over SSNA is that it produces quite simple and short code in programming languages with built-in matrix calculations (MATLAB, internal languages of advanced programmable calculators, etc.) and because it starts with exactly the same input data like the standard NA algorithm, without the need for additional preprocessing of input data. The method is therefore appropriate for writing programs for programmable calculators for solving small-size circuits (e. g. classroom examples), but which may contain singularities. Pseudo-code of this algorithm is given in Fig. 3. Input: A, Zb, Eb, Ac, Jc Output: Vn, Jb Ybp ← (Zb + g –1 I)–1 Ynrx ← A– Ybp + g A+ Ynxr ← Ybp A–T + g A+T Znri ← (A– Ybp A–T – g A+ A+T)–1 Vna ← Znri (A– Ybp Eb + Ac Jc) Vnx ← (Ybp – g I – Ynxr Znri Ynrx)–1 (Ybp Eb – Ynxr Vna) Vn ← Vna – Znri Ynrx Vnx Jb ← g (A+T Vn – Vnx) Fig. 3. Pseudocode of CSNA. Here, I is the unit matrix having the same dimensions as the matrix Zb, while g can be in principle any value at all, but for the numerical stability, it is recommended to be of the same order of magnitude as the average circuit admittance. A+ and A– are matrices obtained taking only positive or only negative elements from As respectively (in analytic form, this means that (A+)i, j = max {(A)i, j , 0} or A+ = (A + | A |) / 2 where | A | is a matrix consisting of absolute values of elements in A, while A– = A – A+). As an example, a MATLAB implementation of this algorithm is given in Fig. 4. function [Jb,Vn]=CSNA(A,Zb,Eb,Ac,Jc) g=1; Ap=(A+abs(A))/2; Am=A-Ap; Ybp=inv(Zb+eye(size(Zb))/g); Ynrx=Am*Ybp+g*Ap; Ynxr=Ybp*Am'+g*Ap'; Znri=inv(Am*Ybp*Am'-g*Ap*Ap'); Vna=Znri*(Am*Ybp*Eb+Ac*Jc); Vnx=(Ybp-g*eye(size(Zb))-Ynxr*Znri*Ynrx)... \(Ybp*Eb-Ynxr*Vna); Vn=Vna-Znri*Ynrx*Vnx; Jb=g*(Ap'*Vn-Vnx); Fig. 4. MATLAB implementation of CSNA. The calculation can be slightly speeded up if certain results occurring in more than one place (like A– Ybp or Znri Ynrx) are cached, but due to the simplicity, it has not been done in this code. Moreover, if the matrix Zb is symmetrical, which is always the case if the circuit does not contain dependent sources, the algorithm can be additionally simplified and shortened. Namely, it is easy to show that the assumption Zb = ZbT directly implies Ynxr = YnrxT so the matrix Ynxr need not to be neither computed nor recorded. Extra simplification is also possible in the case when Zb is a diagonal matrix (i. e. when no inductive coupling or dependent sources exist), as well as in some other special cases. Note that calculation of Vnx in above MATLAB code is also expressed using the matrix left division operator. It is also possible to avoid calculation of Znri using matrix inversion and to calculate Vna and the product Znri Ynrx using the matrix left division too (with careful coding using augmented matrices, both calculations may be performed using only one matrix left division). This can also slightly speed up the calculation and improve the accuracy. Finally, as CSNA is surely much slower than ordinary NA, it is possible to check whether Zb is singular or not, and apply CSNA only if it is singular, otherwise apply the ordinary NA. The SSNA algorithm is a little more complex than CSNA, but it is also much faster, usually only slightly slower than ordinary NA. Its main shortcoming is requirement that the circuit branches should be classified in Nbr regular branches that do not cause problems in the ordinary NA analysis and Nbs = Nb – Nbr potentially singular branches, that may lead to a problem. The second group surely contains all branches with zero impedance, but it also contains branches with tightly coupled inductors. It is not a problem if a regular branch is placed among the potentially singular ones, except for slowing down the algorithm as the number of singular branches increases, but all really singular branches must be included in this group. Actually, CSNA is just a special case of SSNA with a pessimistic approach, taking all branches as potentially singular (in other words, taking Nbr = 0 and Nbs = Nb). For practical use of SSNA, potentially singular branches should also be regular branches with significantly smaller impedance than the typical values in the circuit (i. e. branches with nearly ideal voltage sources, conducting diodes using linearized diode models, etc.) since such branches can introduce severe numerical instability in the classical node potential method. Since SSNA algorithm requires separation of branches in the group of regular ones and the group of potentially singular ones, the input data in this case instead of A, Zb and Eb is contained in Ar, As, Zbr, Zbs, Ebr and Ebs, matrices defined in an analogous fashion as A, Zb and Eb, but taking in account only regular or only potentially singular branches. Similarly, as the output, we get two vectors Jbr and Jbs representing currents through regular and singular branches respectively instead of one vector Jb of all branch currents. Pseudo-code of this algorithm is shown in Fig. 5. Input: Ar, As, Zbr, Zbs, Ebr, Ebs, Ac, Jc Output: Vn, Jbr, Jbs Ybr ← Zbr–1 Ybsp ← (Zbs + g –1 I)–1 Ynrx ← As– Ybsp + g As+ Ynxr ← Ybsp As–T + g As+T Znri ← (Ar Ybr ArT + As– Ybsp As–T – g As+ As+T)–1 Vna ← Znri (Ar Ybr Ebr + As– Ybsp Ebs + Ac Jc) Vnx ← (Ybsp – g I – Ynxr Znri Ynrx)–1 (Ybsp Ebs – Ynxr Vna) Vn ← Vna – Znri Ynrx Vnx Jbr ← Ybr (Ebr – ArT Vn) Jbs ← g (As+T Vn – Vnx) Fig. 5. Pseudocode of SSNA. If we desire the input data to be A, Zb and Eb like in NA or CSNA, then additional (simple) preprocessing is obviously needed to extract relevant matrices from the given input. MATLAB implementation of CSNA is simple as well, assuming the input data is given in the form described above that CSNA expects. Such implementation is shown in Fig. 6. function [Jbr,Jbs,Vn]=SSNA(Ar,As,Zbr,Zbs,... Ebr,Ebs,Ac,Jc) g=1; Asp=(As+abs(As))/2; Asm=As-Asp; Ybr=inv(Zbr); Ybsp=inv(Zbs+eye(size(Zbs))/g); Ynrx=Asm*Ybsp+g*Asp; Ynxr=Ybsp*Asm'+g*Asp'; Znri=inv(Ar*Ybr*Ar'+Asm*Ybsp*Asm'-... g*Asp*Asp'); Vna=Znri*(Ar*Ybr*Ebr+Asm*Ybsp*Ebs+Ac*Jc); Vnx=(Ybsp-g*eye(size(Zbs))-Ynxr*Znri*Ynrx)... \(Ybsp*Ebs-Ynxr*Vna); Vn=Vna-Znri*Ynrx*Vnx; Jbr=Ybr*(Ebr-Ar'*Vn); Jbs=g*(Asp'*Vn-Vnx); Fig. 6. MATLAB implementation of SSNA. As usual, in the above implementation, one multiplication of an inverse matrix with a vector is replaced with much faster and accurate matrix left division. This algorithm as well may be additionally simplified for symmetric matrices Zbr and Zbs i. e. in a case when there are no dependent sources in the circuit, as in such case we have Ynxr = YnrxT too. Of course, caching some intermediate results like As– Ybsp or Ynxr Znri can slightly speed up the calculation. Further significant simplification is possible in a very common case when Zbs = 0 (e. g. when there is no dependent sources nor tightly coupled inductors). Really, in such case we have Ybsp = g I, Ynrx = g As and Ynxr = g AsT. This means that all of these matrices need not to be calculated nor stored at all. Instead, these relations should be inserted into the expressions for other quantities. This will simplify the used expressions, especially the expression for Vnx, which will become simply Vnx ← –(g AsT Znri As)–1 (Ebs – AsT Vna). Note also that some matrices like Ar Ybr ArT may also be read directly from the circuit itself, similarly as in ordinary NA. III. PROOF OF CORRECTNESS OF THE ALGORITHM This section will offer a constructive proof for the validity of the presented algorithms. The proof will be given only for the SSNA algorithm, since CSNA may be considered as a special case of SSNA where As = A, Zbs = Zb and Ebs = Eb, while the matrices Ar, Zbr i Er do not exist, so the members containing them do not exist as well. Assuming that the branches are already separated in the classes of the regular and the potentially singular ones, the matrices A, Zb and Eb can be represented as follows, where 0 denotes null-matrices with appropriate dimensions: 0 ⎞ ⎛Z A = (A r A s ) , Zb = ⎜ b r ⎟ , Eb = 0 Z bs ⎠ ⎝ ⎛ Eb r ⎞ ⎜E ⎟ ⎝ bs ⎠ (2) The branch currents and all node potentials will not change if every branch is substituted with a serial combination of two branches, first being identical to the original one, but with the impedance increased by an amount r, while the other branch consist only of an impedance –r (it is just a mathematical transformation, so the question of such impedance's physicality is not an issue). This transformation effectively represents a substitution of matrices A, Zb, Eb, Ac and Jc with matrices Aaug, Zbaug, Ebaug, Acaug and Jcaug, where − +⎞ ⎛ Aaug = ⎜⎜ A r A s A s ⎟⎟ , Zbaug = ⎝ 0 I −I ⎠ 0 0 ⎞ ⎛ Zb r ⎜ 0 Z + rI 0 ⎟, bs ⎟ ⎜⎜ 0 − r I ⎟⎠ ⎝ 0 ⎛ Eb r ⎞ ⎛A ⎞ Ebaug = ⎜ Eb s ⎟ , Acaug = ⎜ c ⎟ , Jcaug = Jc ⎜⎜ ⎟⎟ ⎝ 0⎠ ⎝ 0 ⎠ Jnaug = Aaug Ybaug Ebaug + Acaug Jcaug = (3) Here, 0 and I represent generic notation for a null-matrix and a unit-matrix of appropriate dimensions. As+ and As– are matrices obtained taking only positive or only negative elements from As respectively. Furthermore, we obtain ⎛ Yb r 0 0 ⎞ Ybaug = Zbaug–1 = ⎜⎜ 0 Yb s p 0 ⎟⎟ ⎜ 0 0 −g I ⎟ ⎝ ⎠ –1 Zbr–1, where Ynaug = Aaug Ybaug AaugT = (5) (18) where, denoting Vna = Znri Jn, = Znx (Jnx – Ynxr Znri Jn) = Znx (Ybsp Ebs – Ynxr Vna) (19) = (Znri – Znrx Ynxr Znri) Jn + Znrx Jnx = = Vna + Znrx (Jnx – Ynxr Znri Jn) = (20) = Vna – Znri Ynrx Znx (Jnx – Ynxr Znri Jn) = = Vna – Znri Ynrx Vnx (6) Ynrx = As– Ybsp + g As+ (7) Ynxr = Ybsp As–T + g As+T (8) Ynx = Ybsp – g I (9) Now, using Schur's formula for the block matrix inversion [10], we can write (10) Here, Vn is the vector of node potentials for regular nodes, while Vnx is the vector of potentials of fictitious added nodes. Although Vnx for itself is not needed for anything, it will occur in the expression for the branch currents. Indeed, augmented branch current vector is: Jbaug = Ybaug (Ebaug – AaugT Vnaug) = T ⎡ ⎤ ⎛ 0 ⎞⎟ ⎛ Yb r 0 0 ⎞ ⎢⎛ Eb r ⎞ ⎜ A r ⎥ V ⎜ ⎟ ⎛ ⎞ −T ⎜ ⎟ = ⎜ 0 Yb s p 0 ⎟ ⎢ Eb s − ⎜ A s I ⎟ ⎜ n ⎟⎥ = ⎜ ⎟ V ⎟ ⎝ nx ⎠⎥ ⎜ 0 0 − g I ⎟ ⎢⎜ 0 ⎟ ⎜⎜ + T − I⎟ ⎠ As ⎝ ⎠ ⎢⎝ ⎥⎦ ⎝ ⎠ (21) ⎣ ⎛ ⎞ Yb r (E br − A r T Vn ) ⎜ ⎟ − T = ⎜ Yb sp (E bs − A s Vn − Vnx ) ⎟ ⎜ ⎟ ⎜ ⎟ g ( A +T Vn − Vnx ) ⎝ ⎠ we have Znx = (Ynx – Ynxr Znri Ynrx)–1 (11) Znrx = – Znri Ynrx Znx (12) Znxr = –Znx Ynxr Znri (13) Znr = Znri – Znrx Ynxr Znri (14) For the augmented node currents matrix, we may write (17) Vn = Znr Jn + Znrx Jnx = Ynr = Ar Ybr ArT + As– Ybsp As–T – g As+ As+T where, denoting Znri = Jnx = Ybsp Ebs Vnx = Znxr Jn + Znx Jnx = –Znx Ynxr Znri Jn + Znx Jnx = where the following notation is used: Ynr–1, (16) ⎛Z Z ⎞⎛J ⎞ ⎛V ⎞ Vnaug = Znaug Jnaug = ⎜ nr nrx ⎟ ⎜ n ⎟ = ⎜ n ⎟ ⎝ Znxr Znx ⎠ ⎝ J nx ⎠ ⎝ Vnx ⎠ ⎛Y Y ⎞ = ⎜ nr nrx ⎟ ⎝ Ynxr Ynx ⎠ ⎛Z Z ⎞ Znaug = Ynaug–1 = ⎜ nr nrx ⎟ ⎝ Z nxr Z nx ⎠ Jn = Ar Ybr Ebr + As– Ybp Ebs + Ac Jc Now, for the augmented node potentials vector we have where Ybr = Ybsp = (Zbs + r I) and g = r . Now we can make the augmented matrix of node admittances as − +⎞ ⎛ = ⎜⎜ A r A s A s ⎟⎟ ⎝ 0 I −I ⎠ ⎛ Eb r ⎞ ⎜ E ⎟ + ⎛ Ac ⎞ J = (15) ⎜⎜ b s ⎟⎟ ⎜⎝ 0 ⎟⎠ c ⎝ 0 ⎠ (4) –1 ⎛ Yb r 0 0 ⎞ ⎛ A r T 0 ⎞ ⎟ ⎜ ⎟ ⎜ −T I ⎟ = ⎜ 0 Yb s p 0 ⎟ ⎜ A s ⎜ 0 0 − g I ⎟ ⎜⎜ + T ⎟ ⎝ ⎠ ⎝ A s − I ⎟⎠ 0 0 ⎞ − + ⎞ ⎛ Yb r ⎛ = ⎜⎜ Ar As As ⎟⎟ ⎜⎜ 0 Yb s p 0 ⎟⎟ ⎝ 0 I − I ⎠ ⎜ 0 0 −g I ⎟ ⎝ ⎠ J ⎛ ⎞ = ⎜ n⎟ ⎝ J nx ⎠ However, since it is obvious that ⎛ J br ⎞ Jbaug = ⎜⎜ J bs ⎟⎟ ⎜J ⎟ ⎝ bs ⎠ it implies that (22) Jbr = Ybr (Ebr – ArT Vn) (23) while for Jbs we obtain two equivalent expressions, where the second one is more suitable since it is simpler: Jbs = Ybsp (Ebs – As –T Vn – Vnx) (24) Jbs = g (As+T Vn – Vnx) (25) Now, the correctness of the algorithm follows directly from the relations derived above. Of course, to reduce the number of variables that appear in the algorithm, some of them that appear at only one place are directly substituted in expressions. Let us analyze the dimensions of the auxiliary matrices that appears in the algorithm. Dimensions of the matrices Ybr, Ybsp, Ynrx and Ynxr are respectively Nbr × Nbr, Nbs × Nbs, Nn × Nbs and Nbs × Nn, and for the matrices Znri and Znx their dimensions are respectively Nn × Nn and Nbs × Nbs. Obviously, the dimensions of the most of these matrices (including matrices that appear as intermediate results), as well as the time of their computation is directly dependent of the number of branches that are declared as potentially singular. The best example is the calculation of the vector Vnx. As the matrix Znx is implicitly involved in this calculation, it requires solving of a system of Nbs linear equations (unlike calculating the matrix Znri which requires inversion of an Nn × Nn matrix independently of the number of potentially singular branches). In conservative SNA we have Nbs = Nb, so the calculation of Vnx requires solving of a rather big system with Nb equations, which may be a problem since we usually have Nb >> Nn. For that reason, CSNA is appropriate only in the cases where the simplicity of the implementation is the most important factor, and the circuits that need to be solved are small in size. Finally, the possibility of SNA algorithm failure has to be investigated. As far as the SSNA variant is concerned, it can certainly fail in a case when any of the singular branches is not properly identified as such, because it makes the matrix Zbr singular. However, assuming the correct identification of the singular branches, as when CSNA algorithm is used, the only possibility of the algorithm failure is in a case when the matrix Ynaug becomes singular. Nevertheless, it is not hard to see that this matrix has to be regular in all cases when the circuit makes sense, i. e. when there are sensible solutions for all node potentials and branch currents. Two pathological cases of SNA algorithm failure should be emphasized, in which sensible solutions for the circuit do not exist at all. The first case is a configuration in which some of the nodes have no path to the reference node, so the potentials of these nodes with respect to the reference node cannot be determined (in that case, the circuit breaks apart into more unconnected circuits). Although such situation is possible, it is not difficult to show that in a such case the matrix Ynaug becomes singular (the linear dependence between its rows/columns arises), so the SNA method fails (just like all other methods for the electrical circuits analysis). Such situation is easily settled adding fictitious branches that connect separated parts of the circuit (through such branches the current cannot flow since there is no closed cycle through these branches). Another situation in which SNA method fails is one in which there are parallel branches with zero impedance, or more general, a contour in which the total impedance is zero. In such cases, matrix Ynaug becomes singular as well. However, in such situations the circuit makes no sense either way, so the solution is impossible to find. Indeed, if there is a branch with zero impedance, its ends may be on different potentials only if it has an ideal voltage source connected in parallel (also a zero impedance branch), e. g. short-circuited ideal voltage source or two ideal voltage sources in parallel. However, in such cases the current through such branch becomes infinite, which makes no sense. On the other hand, if two zero impedance branches in parallel connect points with the same potential, the currents through such branches may be finite, but their exact amounts are impossible to calculate (only their sum can be determined based on the rest of the circuit and Kirchhoff current law), since their ratio depends on the ratio of the values of the branch impedances, which is indeterminate. So, a situation with an impossible solution rises again. Similar reasoning holds for contours with total zero impedance as well. So, SNA method fails only in cases which make no sense anyway, i. e. artificial cases without clearly determined solutions. IV. EXAMPLES CSNA and SSNA algorithms will be illustrated through two examples. The first example is a simple circuit shown in Fig. 7, which can easily be solved even mentally, without taking notes, but it can serve as an illustration of the flow of the algorithm. The only problems in this circuit are the ideal voltage source between nodes 1 and 2 and the short circuit between nodes 3 and 0. Of course, this short circuit could can be simply evaded taking node 3 and node 0 as one, but they are deliberately treated as different in order to show that this does not affect the algorithm. I1 1 8 1 I3 + 2 I5 I2 + 2 20 4 I4 32 4 I6 0 + 3 Fig. 7. Simple example of circuit with singularities In this example, CSNA input data is the same as in case of the classical NA algorithm: ⎛1 −1 −1 0 0 0 ⎞ A = ⎜ 0 0 1 −1 −1 0 ⎟ , ⎜ 0 0 0 1 1 −1⎟ ⎝ ⎠ ⎛1 ⎜0 ⎜ Zb = ⎜ 00 ⎜0 ⎜0 ⎝ 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 4 0 0⎞ ⎛ 20 ⎞ ⎜ 0 ⎟ 0⎟ 0⎟ , E = ⎜ 8 ⎟ b ⎜ 0⎟ 0 ⎟ ⎜ −32 ⎟ 0⎟ ⎜ 0 ⎟ 0 ⎟⎠ ⎠ ⎝ The execution of the CSNA algorithm produces the following matrices, respectively: ⎛1 0 0 0 0 0⎞ A+ = ⎜ 0 0 1 0 0 0 ⎟ , A– = ⎜0 0 0 1 1 0⎟ ⎝ ⎠ ⎛15 0 ⎜ 0 10 1 ⎜0 0 Ybp = ⎜ 0 0 30 ⎜0 0 ⎜0 0 ⎝ 0 0 30 0 0 0 ⎛ 0 −1 −1 0 0 0 ⎞ ⎜ 0 0 0 −1 −1 0 ⎟ , ⎜ 0 0 0 0 0 −1⎟ ⎝ ⎠ 0 0 0 6 0 0 0 0 0 0 6 0 0⎞ 0⎟ 0⎟ 0 ⎟, 0⎟ 30 ⎟⎠ ⎛15 −5 −15 0 0 0 ⎞ ⎛9 0 0 ⎞ Ynrx = YnrxT = 1 ⎜ 0 0 15 −3 −3 0 ⎟ , Znri = 1 ⎜ 0 −5 0 ⎟ 15 ⎜ 0 0 0 15 15 −15⎟ 3 ⎜ 0 0 −3 ⎟ ⎝ ⎠ ⎝ ⎠ ⎛ 4⎞ ⎜ − 6⎟ ⎜ 18 ⎟ 1 ⎛ −72⎞ Vna = ⎜ ⎟ , Vnx = ⎜ − 5 ⎟ − 32 3⎝ ⎠ ⎜ ⎟ ⎜ 3⎟ ⎝ − 2⎠ In the end, we obtain a solution in the following form: ⎛ 8 ⎞ ⎛ 12 ⎞ ⎜ ⎟ ⎜ ⎟ Vn = 20 , Ibr = ⎜ 65 ⎟ , Ibs = ⎛⎜ 22 ⎞⎟ ⎜0⎟ ⎝ ⎠ ⎜ −3 ⎟ ⎝ ⎠ ⎝ ⎠ It can be seen we get practically the same solution as with CSNA method, only having currents through regular and singular branches separated. Note that here we manipulated with matrices of much smaller dimensions. Another example is the circuit shown in Fig. 8 that contain few different singularities: an ideal voltage source in branch 8, an ideal current-controlled voltage source in branch 2, a pair of perfectly coupled inductors in branches 3 and 7, and a short circuit in branch 10. Note that the current in branch 9, although in short circuit, is not zero, due to the presence of inductive coupling. However, if we simply merge nodes 5 and 6 into one node, this branch would remain isolated from the rest of the circuit and the current running through it would have to be determined indirectly. Finally, we obtain the vector of node potentials and the vector of branch currents, representing the solutions: ⎛ 12 ⎞ Vn = ⎜ 20 ⎟ , ⎜0⎟ ⎝ ⎠ 0 2 0 0 0 0 4 0 0⎞ 0⎟ , 0⎟ 4 ⎟⎠ ⎛⎜ 8 ⎞⎟ ⎝0⎠ The execution of the SSNA algorithm produces the following matrices, respectively: ⎛4 0⎞ ⎛ −1 0 ⎞ ⎜ 1 – ⎜ ⎟ ⎟ 0 , As = 0 0 , Ybr = ⎜ 0 ⎟ ⎜ ⎟ 4 ⎜0 0⎠ ⎝ 0 −1 ⎠ ⎝0 Ybsp = ⎛⎜ 1 ⎝0 2 0 2 0 0 0 0 1 0 0⎞ 0⎟ , 0⎟ 1 ⎟⎠ 0 ⎞ , Y = Y T = ⎛⎜ −11 00 ⎞⎟ , nrx nrx 1 ⎟⎠ ⎜ 0 −1 ⎟ ⎝ ⎠ ⎛ 24 ⎞ ⎛4 0 0 ⎞ ⎞ Znri = 1 ⎜ 0 −15 −5 ⎟ , Vna = 1 ⎜ − 40⎟ , Vnx = ⎛⎜ 18 −2 ⎟⎠ ⎟ ⎜ 10 ⎜ 0 −5 −5 ⎟ ⎝ 5 − 40 ⎝ ⎠ ⎠ ⎝ 8j I7 –3j 4 I 3 8 k37=1 + 5 I4 + 2+3j ⎛1 ⎛ 1 −1 0 0 ⎞ ⎛ −1 0 ⎞ ⎜ Ar = ⎜ 0 0 −1 −1 ⎟ , As = ⎜ 1 0 ⎟ , Zbr = ⎜ 00 ⎜0 0 1 1 ⎟ ⎜ 0 −1 ⎟ ⎜0 ⎠ ⎠ ⎝ ⎝ ⎝ ⎛0 = ⎜1 ⎜0 ⎝ 3I5 I 2j 1 3 4 I1 In order to apply SSNA algorithm, the branches 3 and 6 will be declared as singular, others being regular. This makes the input data as follows: As+ + I6 ⎛ 8 ⎞ ⎜ 6 ⎟ ⎜ ⎟ Ib = ⎜ 52 ⎟ ⎜ −3 ⎟ ⎜ 2 ⎟ ⎝ ⎠ ⎛ 20 ⎞ ⎜ ⎟ Zbs = ⎛⎜ 00 00 ⎞⎟ , Ebr = ⎜ 00 ⎟ , Ebs = ⎝ ⎠ ⎜ −32 ⎟ ⎝ ⎠ I2 k49=0.5 I10 2 2j 0 1 I5 4 I9 3 I11 5 2j 6 Fig. 8. Example of circuit with different kinds of singularities The input data for the CSNA algorithm is as follows: ⎛ 1 −1 −1 −1 0 0 0 0 0 0 0 ⎞ ⎛0⎞ ⎜ 0 1 0 0 0 −1 −1 0 0 0 0 ⎟ ⎜0⎟ ⎜ ⎟ ⎜ −1⎟ − 0 0 1 0 0 1 0 1 0 0 0 A =⎜ ⎟ , Ac = ⎜ ⎟ , Ic = (2 ) , 0 ⎜ 0 0 0 0 −1 0 0 0 0 0 1 ⎟ ⎜1⎟ ⎜ 0 0 0 0 0 0 1 1 −1 −1 0 ⎟ ⎜0⎟ ⎜ 0 0 0 0 0 0 0 0 1 1 −1⎟ ⎝ ⎠ ⎝ ⎠ ⎛4 ⎜0 ⎜0 ⎜ ⎜0 ⎜0 Zb = ⎜ 0 ⎜0 ⎜0 ⎜0 ⎜0 ⎜0 ⎝ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 −3 2j 0 0 0 2j 0 0 0 1 0 0 0 4j 0 0 0 0 0 0 −j 0 0 0 0 0 0 0 0 0 0 0 0 0⎞ ⎛ 2+3 j⎞ ⎜ 0 ⎟ 0 0 0 0 0 0⎟ ⎜ 0 ⎟ 0 4 j 0 0 0 0⎟ ⎟ ⎜ 0 ⎟ 0 0 0 − j 0 0⎟ ⎜ 0 ⎟ 0 0 0 0 0 0⎟ ⎜ 0 ⎟ , E = b −3 j 0 0 0 0 0 ⎟ ⎜ 0 ⎟ 0 8j 0 0 0 0⎟ ⎜ 4 ⎟ 0 0 0 0 0 0⎟ ⎜ 0 ⎟ 0 0 0 5+ 2 j 0 0 ⎟ ⎜ 0 ⎟ ⎟ ⎜ 0 ⎟ 0 0 0 0 0 0⎟ ⎝ ⎠ 0 0 0 0 0 3⎠ Due to the size of matrices employed in calculations, only the final results will be shown. The application of CSNA algorithm leads to the following results: ⎛ 0.86553+ 0.75067j ⎞ ⎜ − 0.93302+ 1.66867j ⎟ ⎜ ⎟ ⎜ 1.86700−1.669061j ⎟ ⎛ −1.46212− 0.00270j ⎞ ⎜ − 0.06845+ 0.75105j⎟ ⎜ 1.33983− 0.00385j ⎟ ⎜ 0.93398− 0.00039j ⎟ ⎟ ⎜ − 0.26407− 0.00154j⎟ Vn = ⎜ , Ib = ⎜ 0.00077+ 0.53463j ⎟ ⎜ − 0.93379+ 1.13404j ⎟ ⎜ 0.93398− 0.00039j ⎟ ⎜ ⎟ ⎜ 3.73593− 0.00154j ⎟ ⎜ 3.73593− 0.00154j ⎟ ⎜ − 0.13223−1.13443j ⎟ ⎠ ⎝ ⎜ − 0.13421+ 0.03999j ⎟ ⎜ 1.06820− 0.04038j ⎟ ⎜ 0.93398− 0.00039j ⎟ ⎝ ⎠ In order to apply the SSNA algorithm, the branches 2, 3, 5, 7, 8 i 10 should be isolated as singular ones. Note that branch 5 has to be taken as singular as well, since the current in this branch controls the ideal dependent voltage source in branch 2 (otherwise, the matrix Zbs cannot be extracted). This makes the input data for SSNA as follows: ⎛1 ⎜0 ⎜ Ar = ⎜ 00 ⎜0 ⎜0 ⎝ −1 0 0 0 0 0 ⎛4 ⎜0 ⎜ Zbr = ⎜ 0 ⎜⎜ 0 ⎝0 0 2j 0 −j 0 0 −1 1 0 0 0 0 0 0 0 −1 1 0⎞ 0⎟ 0 ⎟, A = s 1⎟ 0⎟ −1⎟⎠ ⎛ −1 ⎜1 ⎜0 ⎜0 ⎜0 ⎜0 ⎝ 0 0 0⎞ 0 − j 0⎟ −3j 0 0⎟ , Zbs = ⎟ 0 5+2 j 0⎟ 0 0 3⎟⎠ −1 0 1 0 0 0 0 0 0 −1 0 0 ⎛0 0 ⎜0 2j ⎜0 0 ⎜0 4j ⎜ ⎜0 0 ⎝0 0 0 −1 0 0 1 0 −3 0 1 0 0 0 0 0 −1 0 1 0 0⎞ 0⎟ 0 ⎟, 0⎟ −1⎟ 1 ⎟⎠ 0 0 0⎞ 4 j 0 0⎟ 0 0 0⎟ , 8 j 0 0⎟ ⎟ 0 0 0⎟ 0 0 0⎠ ⎛0⎞ ⎛ 0⎞ ⎛ 2+3j ⎞ ⎜0⎟ ⎜ 0⎟ ⎜ 0 ⎟ ⎜ −1⎟ ⎟ ⎜ 0 Ebr = ⎜ 0 ⎟ , Ebs = ⎜ 0 ⎟ , Ac = ⎜ ⎟ , Ic = (2) 0 ⎜ 0 ⎟ ⎜1⎟ ⎜ 4⎟ ⎜ 0 ⎟ ⎟ ⎜ ⎜ ⎟ ⎝ ⎠ ⎝ 0⎠ ⎝0⎠ As the result of the algorithm, we obtain exactly the same solution as in the previous case, but where the currents through regular and singular branches are separated: ⎛ − 1.46212 − 0.00270j ⎞ ⎜ 1.33983− 0.00385j ⎟ ⎟ ⎜ Vn = ⎜ − 0.26407 − 0.00154j⎟ ⎜ 0.93398 − 0.00039j ⎟ ⎜ 3.73593− 0.00154j ⎟ ⎜ 3.73593− 0.00154j ⎟ ⎠ ⎝ ⎛ − 0.93302 + 1.66867 j ⎞ ⎛ 0.86553+ 0.75067j ⎞ ⎜ 1.86700 − 1.669061 j ⎟ ⎜ − 0.06845+ 0.75105j⎟ ⎜ ⎟ ⎜ ⎟ Ibr = ⎜ 0.00077+ 0.53463j ⎟ , Ibs = ⎜ 0.93398 − 0.00039 j ⎟ ⎜ − 0.93379 + 1.13404 j ⎟ ⎜ − 0.13421+ 0.03999j ⎟ ⎜ − 0.13223 − 1.13443 j ⎟ ⎜ 0.93398− 0.00039j ⎟ ⎜ 1.06820 − 0.04038 j ⎟ ⎝ ⎠ ⎝ ⎠ Finally, we need to say something about the execution speed. In addition to the testing in MATLAB, the algorithms given above are also tested on a slow 12 MHz machine, TI–89 Texas Instruments’ programmable calculator, which has a MATLAB-like built-in programming language, as the difference in speed is most noticeable on such machines, and as the primary targets of these algorithms are just programmable calculators. For the circuit in the first example, CSNA was only about 20 % slower than ordinary NA (with slightly perturbed matrix Zb to make it regular), but SSNA was even nearly twice faster than ordinary NA, because it operates with smaller matrices (however, such behavior is not so common). For the circuit in the second example, CSNA was about 2.2 times slower than ordinary NA (with perturbed matrix Zb), but SSNA was only 23 % slower than ordinary NA. V. CONCLUSION In order to give a fair judgment on the contribution that this method brings to the electrical circuit solving, let us once more return to the concept of matrix-based programming, either in MATLAB environment, or in the programmable calculators. The fundamental idea of simplifying calculations through matrix operations, as it was in the era of calculation by hand, remains the same in a matrix-based programming. The matrix operations time complexity gives this approach its legitimacy. The degradation of the speed in the presented algorithms (in comparison with the ordinary NA) is not a big price for the simplicity of the algorithms and the full automatization of the treatment of singular cases. This paper introduced a safe (in terms of the eventual failure of the method) approach for arbitrary linear electrical circuit solving in a matrix-based environment, making it both a powerful solver for calculators with built-in support for matrix calculations or MATLAB based tools, and an interesting topic for both the linear algebra and the electrical circuit theory pedagogical considerations. REFERENCES [1] J. W. Nilsson and S. Riedel, Electric Circuits, 9th ed., Prentice Hall, 2010. [2] C. D. Meyer, Matrix Analysis and Applied Linear Algebra, SIAM, 2000. [3] J. Vlach and K. Singhal, Computer Methods for Circuit Analysis and Design, Van Nostrand Reinhold, 1983. [4] L. O. Chua and P-M. Lin, Computer-aided Analysis of Electronic Circuits: Algorithms and Computational Techniques, Prentice Hall, 1975. [5] L. M. Wedepohl and L. Jackson, “Modified nodal analysis: an essential addition to electrical circuit theory and analysis”, Engineering Science and Education Journal, vol. 11 (3), pp. 84-92, 2002. [6] C-W. Ho, A. E. Ruehli and P. A. Brennan, “The modified nodal approach to network analysis”, IEEE Trans. on Circuits and Systems, CAS-22 (6), 1975. [7] G. Hatchel, R. Brayton and F. Gustavson, “The Sparse Tableau Approach to Network Analysis and Design”, IEEE Transactions on Circuit Theory 18 (1), pp. 101-113, 1971. [8] W. J. McCalla, Fundamentals of Computer-aided Circuit Simulation, Kluwer Academic Publishers, Boston, 1988. [9] G. E. Chatzarakis, “Nodal analysis optimization based on the use of virtual current sources: a powerful new pedagogical method”, IEEE Trans. on Education, vol. 52 (1), pp. 144-150, 2009. [10] E. V. Haynsworth, “On the Schur Complement”, Basel Mathematical Notes, #BNB 20, 1968.