# How to Find Node Voltage in an AC Circuit | Matlab

For Nodal Analysis, the voltage at each node (or junction in the circuit) is identified with respect to ground (node zero). then, circuit equations are written to determine the node voltage. In this tutorial, we will calculate node voltages for the following circuit using Matlab.

Determine the voltage at each node of the circuit of figure:

From above circuit, we can set up the following equations:

\begin{align} & {{I}_{{{R}_{1}}}}={{I}_{{{Z}_{L}}}}+{{I}_{{{Z}_{C}}}} \\ & {{I}_{{{Z}_{L}}}}={{I}_{{{R}_{2}}}} \\ & V={{V}_{A}} \\\end{align}

We can further expand the above mentioned set of equations as:

$\begin{matrix} \begin{matrix} \frac{{{V}_{A}}-{{V}_{B}}}{{{R}_{1}}}=\frac{{{V}_{B}}-{{V}_{C}}}{{{Z}_{L}}}+\frac{{{V}_{B}}}{{{Z}_{C}}} \\ \frac{{{V}_{B}}-{{V}_{C}}}{{{Z}_{L}}}=\frac{{{V}_{C}}}{{{R}_{2}}} \\ V={{V}_{A}} \\\end{matrix} & {} & (2) \\\end{matrix}$

Whereas ZL and ZC can be computed as:

\begin{align} & {{Z}_{C}}={{\left. \frac{1}{j\omega C} \right|}_{\omega =30\text{ krad/s}}} \\ & {{Z}_{L}}={{\left. j\omega L \right|}_{\omega =30\text{ krad/s}}} \\\end{align}

Further, we can rewrite equation (2) in matrix form as:

$[A]=[B]*[C]$

While

$[A]=\left[ \begin{matrix} 0 \\ 0 \\ 1 \\\end{matrix} \right]$

$[B]=\left[ \begin{matrix} -\frac{1}{{{R}_{1}}} & \frac{1}{{{R}_{1}}}+\frac{1}{{{Z}_{C}}}+\frac{1}{{{Z}_{L}}} & -\frac{1}{{{Z}_{L}}} \\ 0 & -\frac{1}{{{Z}_{L}}} & \frac{1}{{{R}_{2}}}+\frac{1}{{{Z}_{L}}} \\ 1 & 0 & 0 \\\end{matrix} \right]$

$[C]=\left[ \begin{matrix} {{V}_{A}} \\ {{V}_{B}} \\ {{V}_{C}} \\\end{matrix} \right]$

Let’s write up some code in Matlab to compute unknowns:

### Matlab Code for Node Voltage Calculation


%Simple AC Circuit 2
clear all;close all;clc
Voltage= 10*exp(j*pi/4); % Source Voltage
R_1= 1e3; % Circuit Resistance R1
R_2= 300; % Circuit Resistance R2
L= 10e-3; % Circuit Impedance (10mH)
C= 0.2e-6; % Circuit Capacitance (0.2 microFarad)
Omega= 30e3; % Angular Frequency
Zc= 1/(j*Omega*C); % Capacitive Reactance
Zl= j*Omega*L; % Inductive Reactance
B=[-1/R_1 (1/R_1+1/Zl+1/Zc) -1/Zl;...
0 -1/Zl 1/R_2+1/Zl; ... % Elements of VA, VB, and VC in equation (2)
1 0 0 ];
A=[0 ; 0; Voltage]; % Inputs Vector (we have only one input voltage source)
C=inv(B)*A;
VA=C(1,1)
VB=C(2,1) % Unknown Node Voltages
VC=C(3,1)
%==============================================


Results:

VA =

7.0711 + 7.0711i

VB =

1.9119 – 0.4552i

VC =

0.7284 – 1.1836i