Basic Linear Algebra: Defining Vectors and Matrices

Vectors and Matrices what are they?

In Matlab everything is defined as either a vector or a matrix therefore it is imperative that you know what Vectors and Matrices are before you begin using Matlab.  The formal definition of a vector is something that has both a direction and a velocity. When using Matlab however, I think it is easier to think of a vector as either a row or a column of values. These values can be names, numbers, or anything you want. There are two kinds of vectors. These are row vectors and column vectors.

A Row Vector is a vector which has only One Row and can have as many columns as one wants. A row vector V with n columns is shown below. (invert the column one below, row vector image missing)

Alternatively, a column vector is a vector which has only ONE Column and can have as many rows as one wants. A column vector V with m rows is shown below.



A matrix is a rectangular array of quantities or expressions. I prefer to think of them as 2-D vectors. Matrices have both numerous rows and columns.

The typical representation of a matrix is m x n meaning the matrix has m rows and n columns.


The subscripts of each element refer to its position in the matrix. Matrices come in all different sizes and shapes. A matrix who has the same number of rows as columns is called a Square Matrix.

How to define Vectors and Matrices in MATLAB

Row Vectors


The use of the semicolon at the end of each line ensures that Matlab will not print off the value of V in the Command Window. If you wish to have it display this value when running, remove the semicolon.

Column Vectors

When defining column vectors in Matlab use the semicolon (;) to separate rows.


Accessing Different Vector Indices

To access different indices in a vector the following notation is used.

To access the third index or the value of 7 in both of the vector examples above one uses V(3). This tells Matlab that you are referencing the third value in the vector V.

Lets say you wish to multiply the third and fourth entry of the vector V and store that value in the first entry. You would type



Matrices in Matlab are defined by combining both row and column vectors. A 3 by 3 matrix in Matlab would be defined as follows.


MATLAB Examples

1) Define a 4 element row vector and then replace the third element by the product of the first and fourth.


2) Define a 3 element column vector and then put the value of 5 into the second element.


3) Define a 4by5 matrix and then make it so when you run the Matlab script, the element in the 3rd row and 2nd column will be printed.


Practice Problems

1) Define a 3 by 2 matrix and replace the value on the second row second column with the value on the third row first column.

2) Define a row vector with 6 elements.

3) Define a column vector with 2 elements and make sure they both print when you run Matlab (Hint: semicolon)

Frequency Response for MOSFET/BJT

The frequency response of a BJT or MOSFET can be found using nearly the exact same process, with the only variations being caused by a single resistor and simple naming conventions that differ between the two devices.

Before we start let’s think a little bit about what we’re doing:
Our goal is going to be to find the pole(s) of the circuit.
Okay? What is a pole and why do I care where it is?
A pole is a frequency at which the gain of the device rolls off. (remember that when it rolls off , it will be at the -3dB frequency with a slope of -20dB/decade)

We care because if the gain of a device rolls off at a certain frequency, then we won’t be able to amplify a signal above that frequency very well because the gain will be decreasing by 20dB/decade.

The procedure is nearly identical whether we are using a BJT of a MOSFET, but we will work each of them side by side just in case there might be any confusion, and we’ll follow these steps as we go through.  (we will also use some values that came from the output file when running a simulation of this circuit in Cadence (or PSPICE) )mosfet-amplifier

1. Take a look at one of the circuits and see what you notice, how about the MOSFET.  This step is just to help us with our knowledge understanding of the circuit.
– At a glance it just looks just like another MOSFET right? Sure is, but let’s take a look at a few things just for kicks. Notice that it is using a bypass capacitor at the source so we don’t have to worry about R_s (at when working with high frequency).  Since the capacitor C_s bypasses R_s to ground, you should notice that this is a common-source amplifier.  You could notice the Values for R_1 and R_2 and start to think about what the Gate voltage is and how that may affect the circuit.
2. We are talking about frequency response so that means we are probably going to want to draw the small signal equivalent circuit.
Remember that the capacitors C_1 and C_2 will act like short circuits at high frequencies so we will ignore them, but we will have to account for some of the capacitance internal to the device.

Both devices have internal capacitances that are very similar.  As you can see from the small signal models for a MOSFET (above) and BJT (below), the only significant difference is that the BJT has an additional resistance Rpi between the Base and Emitter.

Most of the analysis we will do is based on the small signal model. Note that small signal models are not typically used in PSPICE so this picture may look a bit odd, especially the controlled source but for our purpose it is good to have a visual reference. To start we will point out what everything is. Cgs is an internal capacitance betwemosfet-small-signal-model

en the gate and source. The

values for Cgs was similar to one the a PSPICE simulation may give.  CM1 and CM2 are Miller capacitances which we will find values for laterbjt-small-signal-model.  ro is a Norton equivalent resistance that makes the model more ideal.  And just pretend that the G2 looks more like a voltage controlled current source and that their gains are gm*Vgs and gm*Vpi. For the BJT CM1 and CM2 are both Miller capacitances, Cpi is similar to Cgs and Rpi the additional component used for BJTs but not MOSFETs. The other part should look familiar from the other figures.


We will find the device gain, overall gain, equivalent input and output capacitances, and the input and output poles. The process for both is essentially the same.

Device Gain: This is the gain from the control source to the output so we are looking for Vout/Vgs (or Vout/Vpi for a BJT). We will ignore CM2 for this process. Notice the resistances ro, RD, and RL are in parallel. Vout should be given by that equivalent resistance times the current though it which is gm*Vgs from the control source. So the equation for device gain is,

V_{out} / V_{gs} = gm*(r_o//R_D//R_L)   (MOSFET)

V_{out} / V_{\pi} = gm*(r_o//R_C//R_L)   (BJT)

Overall Gain: This will be the gain from the source (Vs) to the output (Vout). We already know what Vout/Vgs is so if we find Vgs/Vs, we can multiply them to get Vout/Vs = (Vout/Vgs) * (Vgs/Vs).  Vgs/Vs is a simple voltage divider. Hopefully you can see this from the small signal model (remember that we are ignoring the capacitors for now but they will play a part later).  The equations we will get for Vgs/Vs and the overall gain are.

V_{gs} / V_s = \frac{ (R_1//R_2)}{(R_1//R_2) + R_s}  (MOSFET)

Overall Gain: V_{out} / V_s = \frac{ (R_1//R_2)}{(R_1//R_2) + R_s} * gm(r_o//R_D//R_L)  (MOSFET)

V_{gs} / V_s = \frac{ (R_1//R_2//r_\pi)}{(R_1//R_2//r_\pi) + R_s}  (BJT)

Overall Gain: V_{out} / V_s = \frac{ (R_1//R_2//r_\pi)}{(R_1//R_2//r_\pi) + R_s} * gm(r_o//R_C//R_L)  (BJT)

Now we will find the input and output poles.  For this we will need to look at the capacitances and use a formula to find the Miller capacitances, CM1 and CM2.  Any explanation for the miller capacitance will have to wait for another post or check out your Electronics Book, Wikipedia, Google, etc. but we will need to use a couple of special equations.  Overall we will need to find the input resistance and input capacitance for the input pole and the output resistance and output capacitance for the output pole.

Each pole will be at a frequency w=1/RC where the R and C are the equivalent R and C at that point, so to find the input pole, we will need to find the input resistance and the input capacitance.  These are found by looking into the input (the left side of the small signal model).  The voltage source will  act like a short so we see Rs in parallel with R1//R2 for the MOSFET (the BJT will have Rpi in parallel also).  The input capacitance will be Cgs in parallel with CM1 (the BJT will be the same).  The output resistance and capacitance are found the same way only looking in from the output (the right side of the small signal model).

\omega_{IN} = \frac{1}{R_{IN}C_{IN}}  \omega_{OUT} = \frac{1}{R_{OUT}C_{OUT}}     (MOSFET or BJT)

So the input pole will be: (MOSFET)

R_{IN} = R_S//R_1//R_2  =  950                                     R_{OUT} = r_o//R_D//R_L =

C_{IN} = C_{gs} + C_{M1}  =                                               C_{OUT} = C_{M2} =

\omega_{IN} =                                                                          \omega_{OUT} =


and the output pole will be: (MOSFET)


R_{IN} = R_S//R_1//R_2//r_\pi =                                  R_{OUT} = r_o//R_D//R_L =

C_{IN} = C_{BE} + C_{M1} =                                                 C_{OUT} = C_{M2} =

\omega_{IN} = \frac{}{}                                       \omega_{OUT} =\frac{}{}

To Do:

finish input & ouput R, input C, Pole (& calculate answers)

BJT Circuit and Symbol Conventions

The following is an explanation of symbol conventions , voltage polarities and current directions for npn and pnp BJTs. The goal is to help understand these characteristics but not on the physical level of electrons and holes. The following figure shows practical operation of each BJT in the active mode.


npn or pnp

When looking at a BJT, the easiest way to decide whether it is npn or pnp is to look at the emitter, which is always modeled as the arrow. If you remember that the arrow tail is always at a ‘p’ node and the tip is at an ‘n’ node, you can easily decide whether the BJT is npn or pnp. Remember that the collector and emitter are always either both ‘n’ or both ‘p’.

Determining Voltage Polarities

It is important to know which direction the voltage’s will appear positive when we begin using nodal analysis to solve BJT circuits. Typically, there will be a voltage drop of .7 V over the |V_{BE}| = |V_{EB}| nodes that will be used in these calculations. Whether |V_{BE}| or |V_{EB}| is positive is decided by the type of BJT. The voltage polarities are flipped between pnp and npn BJTs. Obviously, the only difference in the symbols between the two types of BJTS is the arrow, which is the emitter. If we remember the tip of the arrow is the lower voltage, we are able to deduce that V_{BE} = .7V for an npn BJT and V_{EB} = .7 for pnp.

To be in the active mode, a BJT’s collector-emitter voltage must be above approximately .3 V. As above, this voltage polarity is reversed between npn and pnp BJTs. To determine, whether V_{CE} or V_{EC} should be positive, we can use our deduction of the base-emitter voltage polarity. The voltages, in active mode, drop from collector to base to emitter in npn BJTs and from emitter to base to collector in pnp BJTs. So, if we have figured out that we are using an npn BJT because V_{BE} was a positive .7V, we know that the base voltage is higher than the emitter voltage. From here we know the collector must be higher than the base, and therefore, higher than the emitter. We have just figured out that V_{CE} must be greater than the .3V to be working in active mode. Using the same logic, V_{EC} must be greater than .3V for a pnp BJT to remain in active mode.

Current Flow Directions

Current directions are very simple to figure out. Just use the arrow. The collector and emitter currents always go in the direction of the arrow in active mode. The base current is a little more tricky to figure out, but is also fairly obvious when using the arrow as a reference. As you can see in the above npn circuit, where the arrow is ‘pointing’ away from the base, the base current flows towards the BJT, in the direction the arrow is pointing. Oppositely in the pnp circuit, the base current flows away from the BJT, in the direction the arrow is pointing. There is a table of basic equations listed in my post titled “BJT Transistor Nodal Analysis” which would allow us to calculate each current using a different current, but using Kirchhoff’s Current Law, knowing two currents, we could calculate the third. For a npn BJT, I_E - I_B - I_C = 0 and for a pnp BJT I_C + I_B -I_E = 0 . Note that both of these equations evaluate to I_E = I_C + I_B .

BJT Transistor Nodal Analysis

Basic BJT Equations:

i_C = \alpha i_E \hspace{20 mm} i_B = (1- \alpha ) i_E = \frac{i_E}{\beta + 1} i_C = \beta i_B \hspace{20 mm} i_E = ( \beta + 1) i_B \beta = \frac{ \alpha }{ 1 - \alpha } \hspace{21mm} \alpha = \frac{ \beta }{ \beta + 1 }

It is also important to know that |V_{EB}| = |V_{BE}| can be modeled as .7V .

These equations are not very informative by themselves so a few examples are demonstrated below. In both examples we will assume \beta is very large. What this means for our calculations is i_B \approx 0 . Since i_B \approx 0 we also assume that i_C \approx i_E .

Finding missing voltages in a BJT circuit

Example 1. Solve for V3:

bjt-voltagesThere are several ways to find V_3 . The more “difficult” way is to first find the emitter current, i_E , and then use Ohm’s Law. Since we know i_C \approx i_E , we can find the collector current, i_C , and then solve for V_3 .

\frac{-4-(-10)}{2.4k } = i_C = 2.5mA 12 - (i_E)(5.6k) = 12 - (i_C)(5.6k) = V_3 V_3 = 12 - (2.5mA)(5.6k) = -2 V

The easier way to find V_3 is to recall that |V_{EB}| behaves like a diode. For this pnp BJT: V_{EB} = V_E - V_B = .7 .

We know that V_B = -2.7V so V_E = V_3 = -2 V

\beta may not always be a very large number. Had that been the case here, we would have started by finding the collector current (since it’s voltage drop and resistance are given) and since i_B \neq 0 anymore, we would use the formulas above to the find the base and collector current.

Finding BJT Bias Voltages and Currents

Example 2 Solve for V2 and I1:


Here we will want to start by finding I_1 . I_1 also equals I_E which approximately equals I_C and this collector current will allow us to find V_2 .

I_1 = \frac{10.7-.7}{10k} = 1mA V_2 = (1mA)(10k) - 10.7 = -.7 V

Notice that V_E was given as .7 V .  If this had not been given, we would have been able to find it because V_{EB} = V_E - V_B = .7 V and V_B = 0 V .

Similar to the previous example, if \beta was not a very large number. We would first find the emitter current and then use the equations in the table to find the other branch currents.

Note that both of these examples used pnp BJTs. The difference in an npn BJT is the base-emitter voltage is reveresed. You would use V_{BE} = V_B - V_E = .7 V.

General Rule of Thumb

Most of these problems are very simple to solve. Typically \beta is given and you will need to use Ohm’s Law to identify one of the currents. After one of the currents is found you will be able to solve for the other currents using the basic equations listed above. If one of the currents is not immediately obvious, the base-emitter voltage is likely needed. Most problems have you deduce the emitter voltage from the base, but it is easily possible to find the base voltage from the emitter voltage and then use that to find the base current.

Time Shifting and Scaling of Functions

We’ll begin with a square function, f(t), that has a an amplitude of 1, a start time of 2 seconds and an end time of 4 seconds.


Next, a time shift is demonstrated. Here our function is changed from f(t) to f(t-2). Notice that subtracting 2 from t in the function results in a positive shift of the graph.


In the next two graphs t will be scaled. Scaling t is not quite as intuitive as we may have expected. When we multiply t by 2, corresponding points of the function now occur at 1/2 the time they previously had. When we divide t by 2, each corresponding time on the graph occurs at a t that is now multiplied by 2. Notice that each of these factors directly affects the duration of the signal.


Scaling the amplitude has more intuitive results. If we multiply f(t) by 2, the amplitude of 1 is changed to 2. Multiplying f(t) by 1/2 results in an amplitude of 1/2.


Finally, multiplying t by -1 mirrors our function over the y-axis. Each time now occurs at its negative.



Here we will attempt to convert f(t) into 2*f(.5t+3). The graph of f(t) is shown below.


The easiest way to handle this type of problem without error is to manipulate the function one step at a time. First, I have converted f(t) into 2*f(t). Only the peaks are changed here (by a factor of 2).


Next, I convert 2*f(t) into 2*f( \frac{1}{2} t). Notice how the \frac{1}{2} actually expands our graph duration by a factor of 2 (from a 6 sec duration to a 12 sec duration).


Finally, we move from 2*f( \frac{1}{2} t) to 2*f( \frac{1}{2} t + 3). As shown in the discussion above, this is a time shift. Time shifts can be a little confusing because adding results in a negative shift of our graph. Try to think of it as our signal occurring 3 seconds earlier than before, reading from left to right on the graph. The easiest way to do this part is shift each x-intercept by 3 seconds (to the left, of course).