Category Lesson

Negative Resistor Lesson

This tutorial is going to cover the topic of negative resistance. At first, it might seem like a strange idea that you could have a current flowing in the opposite direction of an applied voltage; but, hopefully by the end of this tutorial you will have a better intuitive understanding of what a negative resistance really is, and how to build a negative resistor out of common circuit components.

  1. What is a Negative Resistance?
  2. Creating a Negative Resistor Using a CCVS
  3. Creating a Negative Resistor Using a VCVS
  4. Creating a Negative Resistor Using Real Components
  5. Example Problem
  6. Summary

What is a Negative Resistance?

Our first step is to try to develop an intuitive notion of what a negative resistance is, and how it would behave in a circuit. The definition of resistance is governed by simple a relationship called Ohm’s Law.

$$R=\frac{V}{I}$$

We can see by looking at this equation, that to create a negative resistance we would need to create a circuit component which develops a negative voltage whenever a positive current is passed through it (assuming passive sign convention). However, rather than thinking about it in terms of mathematics, a simpler way to understand the idea of negative resistance is to consider the resistance of two resistors in series.

From a basic understanding of circuits, we know that the values of resistors add in series. Therefore, if we had a resistor with a positive value of 11 Ohms in series with a resistor with a negative value of -4 Ohms, the equivalent resistance in series comes out to 11 + (-4) = 7 Ohms. In other words, we can think of a negative resistor as a device we can put in series with another resistor to decrease its value.

Example of a negative resistor circuit

Return to Top

Creating a Negative Resistor Using a CCVS

Now that we have an idea of what we are trying to achieve, we can start our quest to create a negative resistor returning to Ohm’s Law and rearranging.

$$R=\frac{V}{I} \Rightarrow V=RI$$

Looking at this equation, we notice that it looks very similar to the equation governing the operation of a current-controlled voltage source (CCVS). In the equation below, $V_{CCVS}$ is the voltage output of the CCVS, $I_c$ is the controlling current, and $r_c$ is the “gain parameter” with units of Ohms—hint, hint!

$$V_{CCVS}=r_c I_c$$

If we make the assumption that the control current $( I_c )$ is flowing into the positive terminal of the CCVS, we can easily calculate the resistance $( R_{CCVS} )$ of the CCVS by once again using Ohm’s Law.

$$R_{CCVS}=\frac{V_{CCVS}}{I_c} = R_c$$

This leads us to the solution that the resistance of a current-controlled voltage source, whose control current is measured at the positive terminal, is simply equal to the gain parameter $( r_c )$ of the CCVS. By utilizing this fact, we can easily create a negative resistor simply by using a CCVS with a negative gain parameter. An example of this method can be seen in the figure below. Here we implement a resistance of -4 Ohms using the CCVS method.

Example of a negative resistor built using using a CCVS

Return to Top

Creating a Negative Resistor Using a VCVS

At this point, some readers might be wondering “why go any further?” Unfortunately, a current-controlled voltage source isn’t a very practical real world circuit component. In fact, many circuit simulation programs (such as LTspice) don’t even include CCVS models! We can, however, overcome this limitation by using a component which is more readily at our disposal: a voltage-controlled voltage source (VCVS).

By looking at the equation governing the operation of a VCVS, we can see that it looks identical to the equation of a voltage amplifier. In the equation below, $V_{out}$ is the voltage output of the VCVS, $V_{sense}$ is the controlling voltage (i.e., the input voltage to an amplifier), and $G$ is the gain parameter (which is a unitless ratio).

$$V_{out}=G V_{sense}$$

With the help of Ohm’s Law (last time, I promise!), we find that we can make the VCVS mimic a CCVS through the use of a sensing resistor $( R_{sense} )$ in series with the VCVS to measure current. The current flowing through $R_{sense}$ will create a voltage which is proportional to the current, and can then be picked up by $V_{sense}$. The proposed setup can be seen in the figure below.

Example of a negative resistor setup using a VCVS

While the above setup gives us a structure that can be used to create a negative resistor, we continue our analysis by developing a set of analytical equations describing this circuit’s operation. The voltage developed across the sense resistor is written below.

$$V_{sense} = I_{sense} R_{sense}$$

We can now take the equation governing the VCVS, make the following substitutions and regroupings, and make the equation look like the equation governing the CCVS.

$$V_{out}=G V_{sense} = G (I_{sense} R_{sense}) = (G R_{sense}) I_{sense}$$

Here we see that $(G R_{sense})$ takes the place of $r_c$ from the CCVS equation. Also, we know from the previous section that $r_c$ is the resistance of the CCVS negative resistor circuit. However, to find the total resistance $R_{total}$ of VCVS circuit we are building, we need to take into account the added resistance of the current sensing resistor $(R_{sense})$.

$$R_{total} = R_{sense}+r_c$$

Making the substitution $r_c = (G R_{sense})$, we obtain:

$$R_{total}= R_{sense}+G R_{sense} = R_{sense}(1+G)$$

From this equation, we can solve for the gain parameter of the VCVS that we would need to create any desired resistance in our circuit.

$$G = \frac{R_{total}}{R_{sense}} – 1$$

Using the set of equations we have developed, we now have the tools to create a negative resistor of any value by using only a VCVS along with a sensing resistor. As an example, we now create a negative resistor with a value of -4 Ohms. By arbitrarily choosing $R_{sense} = 2 \: Ohms$, we can calculate the required gain parameter of the VCVS by using the previous equation.

$$G= \frac{R_{total}}{R_{sense}} – 1 = \frac{-4}{2} – 1 = -3$$

The completed example circuit can be seen below.

Example of a -4 Ohm resistor built using using a VCVS

Return to Top

Creating a Negative Resistor Using Real Components

Now that we have created a theoretical circuit describing a negative resistor, our final step is to create a practical implementation using real world components. To reiterate from the previous section, a VCVS is nothing more than a voltage amplifier with differential input and differential output. To simplify the circuit design, we will make the assumption that one of the terminals of our negative resistor will always be connected to ground. This assumption allows us to use a voltage amplifier which has differential inputs, but only a single ended output. I’ve attached a schematic for an inverting amplifier like this as a reference in the figure below.

A differential input, single sided output, inverting amplifier

The gain of this amplifier is set by the ratio of resistors $R_f$ and $R_1$.

$$G=-\frac{R_f}{R_1}$$

Therefore the input-output relationship of this amplifier is governed by the following equation.

$$V_{out}=-\frac{R_f}{R_1}(V_{in+}-V_{in-})$$

The similarity to the equation governing the VCVS $(V_{out}=G V_{sense})$ is easy to see if we make the following substitutions.

$$G = -\frac{R_f}{R_1}$$

$$V_{sense} = V_{in+}-V_{in-}$$

This allows us to directly substitute for the VCVS in the negative resistor circuit with our differential amplifier circuit. We can solve for the required ratio of $R_f$ to $R_1$ by using the equation used to calculate the required gain of the VCVS in the previous section. The equation is repeated below.

$$G=\frac{R_{total}}{R_{sense}} – 1$$

$$-\frac{R_f}{R_1}=\frac{R_{total}}{R_{sense}} – 1$$

$$\frac{R_f}{R_1}=-\left( \frac{R_{total}}{R_{sense}} – 1 \right)$$

By directly replacing the VCVS from the previous section with the circuit above, we obtain the final schematic for the negative resistor seen below.

A negative resistor implemented using differential amplifier

We find the overall resistance of the circuit by substituting the gain equation of the differential amplifier circuit into the equation for calculating $R_{total}$ of the VCVS circuit developed in previous section.

$$R_{total} = R_{sense}(1+G) = R_{sense}\left(1+ -\frac{R_f}{R_1} \right) $$

Return to Top

Example Problem

To make sure that everything discussed is correct and checks out, we will work out a single example problem and simulate it.

Example: Create a negative resistor with a value of -4 Ohms. Use $R_{sense}=2\: Ohms$, and keep both $10\: kOhms \leq R_1 \leq 1\: kOhms$ and $10\: kOhms \leq R_f \leq 1\: kOhms$. Using Spice, calculate the equivalent series resistance of the negative resistor in series with an 11 Ohm resistor, using a 5 V DC voltage source as the test voltage. The total equivalent resistance should be equal to 11 – 4 = 7 Ohms.

We start by calculating the required gain of the amplifier.

$$G = \frac{R_{total}}{R_{sense}} – 1$$

$$G = \frac{-4}{2} – 1 = -3$$

Now that we know the gain, we can calculate the values of $R_1$ and $R_f$ to set the gain of the differential amplifier circuit. To make our calculations easy, we will choose $R_1 = 10\: kOhms$.

$$G=-\frac{R_f}{R_1}$$

$$-3=-\frac{R_f}{10,000}$$

$$ R_f = 3 \times 10,000 = 30,000\: Ohms$$

Now that we have the values of all the components, we can plug them into our circuit. Here is what we get!

completed example circuit

To verify our results, we run the simulation and everything checks out. Because the differential amplifier has a finite input resistance, this will slightly affect the operation of our circuit. We can take this into account while we are designing our circuit; but, I will leave that as an exercise for the reader (don’t you always love it when textbooks do that).

Return to Top

Summary

As a summary, I will outline our thought process, the steps we took, and the final result so that we can collect our thoughts.

  1. We notice that a current-controlled voltage source has a similar equation to a resistor.
  2. We realize that we can create any value of resistor (both positive and negative) if we use the current flowing into the positive terminal of the CCVS as the sensing current, and choose a suitable gain parameter value.
  3. We can mimic the CCVS using a voltage-controlled voltage source if we use a current sensing resistor.
  4. We can implement a VCVS by using a differential amplifier.
  5. By substituting the VCVS for the differential amplifier, we obtain a practical method to implement a negative resistor.

The negative resistor circuit can be seen below

A negative resistor implemented using differential amplifier

The resistance of the circuit is given by the following equation.

$$R_{total} = R_{sense}\left( 1-\frac{R_f}{R_1} \right) $$

If you have any questions, feel free to either leave a comment below or shoot me an email.

Return to Top

Adding Spice Models to LTspice

Finally… a new tutorial. Who could have ever guessed that life in the real world would be so busy (note the sarcasm!)? This tutorial is going to cover adding custom Spice models into your LTspice simulations and library. While it is very easy once you know how to do it, there are a couple pitfalls that nearly caused me to go crazy and rip my hair out in the past. Hopefully this will save you some time and stress, and possibly a hole in your monitor. Now let’s get started!

  1. Finding and Downloading the Spice Model
  2. Adding the Spice Model to your LTspice Library
  3. Using the Spice Model in a Circuit
  4. Conclusion and tl;dr (too long;didn’t read)

Finding and Downloading the Spice Model

It might seem obvious, but the first thing you need to do is find a suitable Spice model. This can usually be done in one of two ways. The easiest method is to simply Google the phrase “[part I am looking for] spice model”. If the part is popular enough and isn’t some incredibly complex part, your search will usually turn up some hits. The second method is to directly search the part manufacturer’s web page for the part. Sometimes you will have to switch tabs, or it will simply be link on their part’s web page such in the following screenshot:

screenshot of download website

An unfortunate characteristic of the Spice world is that over time it has become fairly fragmented. Different design tools use different versions of Spice, hence, part manufacturers will often have the Spice file for their part available in a couple different formats. The best format to use is the Spice3 model, however the PSpice model will usually work in LTspice as well.

Once you have found the model you want to use, you need to make sure it is in the correct format with the correct extension. A Spice model file is nothing more than a text file with a different extension. In the case of LTspice, if the model file contains only a single model, it should be named with the .sub extension. If the file contains multiple models, then the file should be named with the .lib extension.

I’m not going to go into depth on renaming text file extensions, however one method to do it is to first open up the model in notepad (in Windows 7, right click on the file > open with > notepad). Next, go to file > save as. Where you type the file name in the file name text box, type the exactly desired file name in quotes, and the program will name it exactly that. For example you could type 1N4148.sub. If you tried typing the file name without the quotes you would get 1N4148.sub.txt instead of the desired 1N4148.sub.

Return to Top

Adding the Spice Model to your LTspice Library

For this tutorial we will be using a Spice model for a made up diode called the 1NADAM, named after your beloved engineer, me! You can either download the file here (righ click on link > save as), or simply copy the code below, paste it into a text document, and save it with the .sub (or .lib) extension as explained in the previous section.

*
******************************************
*
*1N4ADAM
*
*
*Spice model for a made up diode used in
*my LTspice adding models tutorial at
*http://www.adamsiembida.com/
*
******************************************
*
.SUBCKT 1NADAM 1 2 
*
*
R1 1 2 5E+9 
D1 1 2 INTDIO
*
.MODEL INTDIO D 
+ IS = 7.0E-9 
+ N = 1.5 
+ BV = 30 
+ IBV = 0.00025
+ RS = 0.20
+ CJO = 5.0E-13 
+ VJ = 0.80 
+ M = 0.030 
+ FC = 0.50
+ TT = 3.0E-9 
.ENDS
*

As you can see, inside of the file for the 1NADAM there are .SUBCKT and .MODEL statements. Most Spice models downloaded from the internet will have .SUBCKT statements, because often time a simple .MODEL statement will not sufficiently model the complex behavior of modern parts. I am assuming that the reader knows the difference between a .SUBCKT and .MODEL (explaining those thoroughly is a topic for another tutorial). In short, however, a .MODEL statement will provide the model for an existing Spice primitive (i.e. a capacitor, resistor, transistor, diode, and so on). While .MODEL statements will work for simple simulations and old parts, it will not be very accurate for newer, smaller parts. For example, transistors have become so small and non-ideal, that the equations which we all learned in textbooks do not provide sufficient accuracy for good simulation results.

This is one case where a .SUBCKT model becomes very useful. This allows a manufacturer or engineer to create a more complex model using more than a single Spice primitive, which will lead to better results. This also allows manufacturers and engineers to create models which take into account any peculiarities or quirks that the component might have. You will be hard pressed to find a model for a real part which uses a single .MODEL statement for the Spice model. Therefore this tutorial assumes a .SUBCKT type model but will point out the difference where applicable.

Once you have the Spice model on your computer, adding it to your LTspice library is very easy. Simply copy the file to your LTC\LTspiceIV\lib\sub folder. Usually the full path to that directory will be either C:\Program Files (x86)\LTC\LTspiceIV\lib\sub on a 64 bit Windows 7 installation or C:\Program Files\LTC\LTspiceIV\lib\sub on a 32 bit (x86) Windows installation.

screenshot of adding model file to correct folder

Return to Top

Using the Spice Model in a Circuit

Now that the Spice model is in your library, there are a couple things you need to do. The first is make the circuit which will contain our part. For example, here is a simple half-wave rectifier I have tossed together.

simple half wave rectifiersimple half wave rectifier

The next is to let LTspice know that you will be using that the newly added file. You do this by placing a Spice directive (s shortcut key, or the .op button on the toolbar) onto the schematic containing .lib FILENAME, using the entire name of the file containing your model. Make sure to include the file extension! This is the first pitfall I was talking about. Here is an example of how to correctly add our new file:

.lib 1NADAM.sub

While the above way is correct, below you can see a common mistake which will not work:

.lib 1NADAM

Here you can see some screenshots showing how to add the spice directive on to the schematic.

adding the .lib directive

.lib directive placed on schematic

In case some of you are wondering what exactly this does, it includes any models included in the specified file into the Spice simulation file. You might also be wondering what the difference between the .LIB and .INC directives is. The .LIB directive will only add models from the specified file. If you had some other directives in there, for example a .TRAN statement, it would be discarded. The .INC directive will include everything in the specified file into your project, regardless if it is a model, directive, netlist, or anything else. So use .LIB just to be safe in case there is some other junk in there (even though there shouldn’t be).

Now that you have added the file, you can simply use any .MODEL or .SUBCKT included in the file as you would with any of the default components. Just right click on a component’s default model (in this case the D right next to the diode), and change its value to the name of the model inside of the file. Alternatively you can hold ctrl then right-click on the symbol and change the value in the Value row). Usually you have to look inside the file using a text editor to see what exactly the author of the Spice file called the model. For example the model for the 1N4148 diode might not actually be called 1N4148 inside of the file.

changing model for diode

Here is also where the second major pitfall comes in.

If you are using a .SUBCKT type model for a Spice primitive, you need to change the Spice prefix on the component!.

What the Spice prefix does is tells LTspice what kind of model to expect for the part. For example, on a diode, the default will be a D because, well, the part is a diode so it expects a diode model. Remember however that we are not using a regular diode model for our diode; we are using a .SUBCKT model. This means that we need to change the Spice prefix to a subcircuit model instead of a diode model. To do this, hold ctrl and then right-click on the symbol in the schematic. Then just double click in the Value cell next to Prefix, and change the value to an X.

changing the prefix

At this point the file should be ready to simulate and look like this:

schematic ready to simulate

Congratulations, everything should be working now! We can run a simulation to see what comes out. Keep in mind that this circuit not meant to be a good rectifier. I purposely chose the values to make it easy to see what this circuit is actually doing just by looking at the output. Here is the result:

simulation results

Return to Top

Conclusion and tl;dr (too long;didn’t read)

This article was much longer than I initially expected, and probably more than was really needed. However, what inspired me to write this tutorial was that when I was just starting to learn LTspice, I would read instructions people posted on forums, but I didn’t exactly understand what all the steps meant or how to perform them. For example I had no idea what “change the Spice prefix to X” meant, and I had no idea that you had to hold ctrl then right-click on the symbol to do it. In summary, here is a quick tl;dr version for people who might already be familiar with Spice and LTspice, and just want the quick and concise procedure. This will also serve as a good recap for people who read the entire article!

  1. Download and rename the Spice model to something that makes sense
  2. Move the Spice model into the sub folder in your LTspice directory
  3. Add a .LIB FILENAME directive onto your schematic
  4. Change the Value field for your symbol to the name of the model inside of your Spice model file
  5. If you are using a .SUBCKT type model for a Spice primitive, hold ctrl then right-click on the symbol and change the Prefix field to X

Good luck! I hope this was helpful!

Return to Top

How to Compute the IFFT using only the forward FFT

How can you calculate the IFFT (Inverse Fast Fourier Transform) using only the forward FFT (Fast Fourier Transform)? It is easier than you think! Read on to find out how.

  1. Cheat-Sheet: Just tell me how!
  2. Derivation of the Method

Cheat-Sheet: Just tell me how!

Let’s start with just saying straight out what you do. Take the input signal, let’s call it x, and take its complex conjugate. Then take the FFT of that result. Then take the complex conjugate again. Finally divide the resultant signal by N (the length of the signal). Here is the formula:

$$IFFT(X) = \frac{1}{N}conj(FFT(conj(X)))$$

Derivation of the Method

Hopefully you are also interested in the why! To start, let’s note that the FFT and DFT (Discrete Fourier Transform), and the IFFT and IDFT (Inverse Discrete Fourier Transform), are identical. The “Fast” in FFT and IFFT just means that the algorithm used to compute the DFT and IDFT is faster than a direct approach, but it still gives the same exact results.

The first thing we will need to do is to find out how the DFT and IDFT are related. Let’s write out the definitions:

$$DFT_N(x) = \sum_{n=0}^\infty x_n e^{-j\frac{2\pi n}{N}k}$$
$$IDFT_N(x) = \frac{1}{N} \sum_{n=0}^\infty X_k e^{j\frac{2\pi n}{N}k}$$
Notice that the only difference between the two is the scaling factor $\frac{1}{N}$ and the sign of the “j” in the exponential term. Using the complex conjugate, we can rewrite the exponential term in the DFT, and we will have:

$$DFT_N(x) = \sum_{n=0}^\infty x_n conj(e^{j\frac{2\pi n}{N}k})$$
This certainly looks more like the IDFT than it did before, but now we need some way to get rid of the complex conjugate. To do this we are going to use a property of complex conjugates:

$$conj(a) conj(b) = conj(ab)$$
So, let’s apply this property. But to do so, we need to first take the complex conjugate of $x_n$.

$$DFT_N(conj(x)) = \sum_{n=0}^\infty conj(x_n) conj(e^{j\frac{2\pi n}{N}k})$$
$$DFT_N(conj(x)) = \sum_{n=0}^\infty conj(x_n e^{j\frac{2\pi n}{N}k})$$
Now it’s time to apply another property of complex conjugates:

$$conj(a) + conj(b) = conj(a + b)$$
Using this property, we can pull the complex conjugate operator to the outside of the sum.

$$DFT_N(conj(x)) = conj(\sum_{n=0}^\infty x_n e^{j\frac{2\pi n}{N}k})$$
Now, take a look again at the definition of the IDFT posted at the start. The contents inside the conj() on the right hand side of the equation, match up with the definition of IDFT multiplied by a factor of N. So we can substitute it in.

$$DFT_N(conj(x)) = conj(N*IDFT_N(X))$$
From here, knowing that since N is real, conj(N) = N, and using some simple algebra, we can get to the final result.

$$DFT_N(conj(x)) = N conj(IDFT_N(X))$$
$$\frac{1}{N} DFT_N(conj(x)) = conj(IDFT_N(X))$$
$$\frac{1}{N} conj(DFT_N(conj(x))) = IDFT_N(X)$$
This is what we were looking for. Therefore we have shown that

$$IFFT(X) = \frac{1}{N}conj(FFT(conj(X)))$$

HP 50g Derivatives, Integrals, and Summations Tutorial

Arguably of the best reasons for getting a calculator with a CAS (computer algebra system) is to solve derivatives, integrals, and summations symbolically. Here’s how to do it with the HP 50g.

  1. Derivatives
  2. Indefinite Integrals
  3. Definite Integrals
  4. Summations

NOTE: This (and all of my other) tutorial assumes that the calculator is in RPN mode. If you are not using RPN mode, take the time to learn it and you will be very glad you did!

Derivatives

To take the derivative of an expression where the independent variable is ‘X’, first enter the expression onto the stack.

Expression to take derivative of

Next press [LSHIFT], then [CALC] to open up the calculus menu. Select {DERVX}, which stands for “derivative with respect to X”, and press the {OK} soft button.

Calculus menu

Hopefully your calculator shows this!

Solution for the derivative

Return to Top

Indefinite Integrals

To take the indefinite integral of an expression where the independent variable is ‘X’, first enter the expression onto the stack.

Expression to take indefinite integral of

Next press [LSHIFT], then [CALC] to open up the calculus menu. Select {INTVX}, which stands for “integral with respect to X”, and press the {OK} soft button.

Calculus menu

Hopefully your calculator shows this!

Solution for the integral

Return to Top

Definite Integrals

To take the definite integral of an expression, open up the equation writer by pressing [RSHIFT] then [EQW]. To enter an integral press [RSHIFT] and then the integral button (same as the [TAN] button). Your calculator should look like this:

Equation writer

Enter values for all the “dots” by entering the desired values and then pressing the [RIGHT ARROW] button to move to the next location. A possible input could look like this.

Expression in the equation writer

It should be noted that in the equation writer the calculator can integrate with respect to any variable, just make sure to put the desired variable in the differential. Once the integral is set up correctly, press [ENTER] to output the expression onto the stack.

Expression on the stack

To evaluate the expression, press [EVAL]. Hopefully your calculator shows this!

Solution for the integral

Return to Top

Summations

Finding the value of a summation is similar to solving a definite integral. Open up the equation writer by pressing [RSHIFT] then [EQW]. To enter an summation press [RSHIFT] and then the sigma button (same as the [SIN] button).

sum1

Enter values for all the “dots” by entering the desired values and then pressing the [RIGHT ARROW] button to move to the next location. A possible input could look like this.

sum2

Press [ENTER] to output the expression onto the stack.

sum3

To evaluate the expression, press [EVAL]. Hopefully your calculator shows this!

sum4

Return to Top

HP 50g Variables and Folders Tutorial

This is a basic tutorial on managing variables and folders on the HP 50g calculator. Deleting variables is easy once you know what to, but it gives people trouble at the start when learning how to use this calculator. Using folders effectively is important because it helps with organizing variables and lets you have more than one sets of variables or constants saved for different types of problems or classes. The file browser is useful for navigating folders but also good for helping you delete large amounts of variables quickly.

  1. Creating and Using Variables
  2. Deleting Variables
  3. Creating Folders
  4. Accessing Variables and Organizing Folders

NOTE: This (and all of my other) tutorial assumes that the calculator is in RPN mode. If you are not using RPN mode, take the time to learn it and you will be very glad you did!

Creating and Using Variables

Creating and using variables is easy to do if you know how. To create a variable, put the contents that you want to store in the variable on the first line of the stack. Next, type in the name of the variable you want to use. The name of the variable can be anything that starts with a letter and be as long as you want, however I suggest you limit it to four characters or less because that’s all that will be displayed when you’re choosing the variable. Once you typed in the name, all you have to do is press STO and the variable will be created.

Creating a variable

To put the contents of the variable onto the stack, press the VAR button, and then press the soft button for the variable you want to use. If there are more than six variables and you want to see more, press NXT and this will show the next six. If you want to put the actual variable name onto the stack as opposed to the contents, for example if you want to save something else into that variable, first press the ‘ (apostrophe) button and then press the variables soft button. There is a very nice shortcut for saving over variables without having to press so many buttons. First make sure that your variables are visible by pressing VAR. Then put the contents that you want to store onto the stack, then press (but don’t hold) the white shift key, and finally press the variables soft button. This will make variables a lot easier to work with.

Overwriting a variable

The HP 50g can sometimes be a finicky calculator, so it is important to know whether to enter the variable with or without apostrophes. If you want to just use the contents of the variable and don’t care about having the symbolic representation, then just use the variable as described in the earlier section. If you want to keep the variable as a symbol until you are ready to evaluate the expression, then enter the variable with the apostrophe. When you are ready to evaluate the expression on the stack, press EVAL, and this will automatically make the appropriate substitutions and evaluate the expression. Another time that the apostrophe is required is in the matrix writer and also when creating a vector. I find it easier, however, to just use the equation writer for inputting expressions into a matrix, as this takes care of all the formatting and apostrophes for you. Another thing that makes matters more confusing is that if the variable being used is is empty, then the calculator will automatically put apostrophes around it for you and just assume it is a symbolic variable.

If you keep these things in mind, you should be able to find your errors should something go wrong!

Return to Top

Deleting Variables

Why does deleting variables require its own section? Because it can be tricky and annoying. I would have thought that when creating this calculator HP would have made some easy and quick way to delete variables without jumping through menus, but as far as I know, they didn’t. It could be that they simply expected the user to overwrite variables instead of deleting and re-creating them. I like to keep my calculator organized and I suggest that you remove any variables that aren’t in use to avoid unexpected behaviors should you make a mistake.

To delete a variable you have to first put the variables symbol on the stack. Like explained above, first press the ‘ button, enter the variables name, and then press ENTER. Once the variable is on the stack, press the TOOL button. Next press the PURGE soft button. This will remove the variable from memory. If you want to delete multiple variables, first put them all on the stack, and then keep pressing PURGE until all of them are gone. Eventually you will become very quick at deleting them and it will be less of a hassle.

Deleting a variable

Another way to delete variables is by using the file browser. This way takes more time for deleting single variables, but can be much faster for deleting large amounts of variables. To open the file browser, press LSHIFT (left shift) and then FILES. This should open up a similar looking screen as below. The only difference will be that I have a folder named WRK that I use to solve random problems in.

The file browser

Now you have to browse to the folder containing the variables. If you have never changed a directory (directory and folder are synonymous) then your variables will be in the “Home” directory. To change directory, highlight the directory you want to switch to using the arrow keys, and then press the OK soft button. Then press ENTER next to any variable or object that you want to delete to select it. A number will appear to the left of any item to indicate that it’s selected.

Choose the variables

Once you have finished making your choices press NXT (which changes to the next page of the soft menus) and then press the PURGE soft button. When it asks you “Are You Sure”, press the ALL soft button. You can also select multiple variables quickly in the file browser by just holding down the ENTER button until it gets to the bottom instead of selecting each variable individually. To exit the file browser press CANCEL (same as the ON button).

Delete all

Return to Top

Creating Folders and Deleting Folders

First you have to open up the file browser. Press LSHIFT and then FILES. Next you have to move to the location that you want to create the folder in. Highlight the directory you want to switch to using the arrow keys, and then press the OK soft button. Press NXT to move to the next page of the soft menu, and then select NEW.

New folder window

Don’t type anything in the “Object:” field. Move down to “Name:” using the arrow keys, type in a name, and press ENTER. Then move down next to “Directory” and press the CHK soft button. If you don’t put a check mark next to “Directory” it won’t work. Then press the OK soft button. The new folder is now created. To switch to that folder to work in, find the folder in the file browser and press the CHDIR soft button. To move up one level of folders, press LSHIFT and then UPDIR. Deleting folders works exactly the same way as deleting variables.

New folder window filled out

Return to Top

Accessing Variables and Organizing Folders

Lastly, a quick note about accessing variables in regards to nested folders. A nested folder is a folder that is inside of another folder. A folder inside of another folder is also said to be at a “lower level” than the “higher level” folder containing it. Variables can be accessed from all higher level folders, but not from lower level folders. This is important because it provides a useful way of organizing folders and variables.

An example of this would be to create a folder called “Electrical Engineering”. Inside of that folder you might want to define some equations or create some custom defined constants that you wouldn’t want to accidentally overwrite. Then inside of the “Electrical Engineering” folder you could create another folder called “Work”. When you are working on electrical engineering you would go into “Electrical Engineering > Work”. Now you are free to create whatever variables you want without overwriting anything else, while still being able to access all of your equations and constants. If you organize different folders like this it will be easy to manage everything without having your calculator become a mess.

Return to Top

HP 50g Basic Graphing Tutorial

Graphing on the HP 50g took me a while to get used to. You have to go through a few separate menus to create a nice looking graph. This threw me for a loop because I was used to a calculator that had most the options for creating a graph in one place. Here is a little guide that will get you acquainted with the very basics of creating a graph on this calculator. There are three main steps.

  1. Entering the function
  2. Setting up the tick marks
  3. Setting up the window
  4. A few tricks

NOTE: This (and all of my other) tutorial assumes that the calculator is in RPN mode. If you are not using RPN mode, take the time to learn it and you will be very glad you did!

Entering the Function

The first step is to enter the function. While holding LS (left shift) press F1. This will open up the list of functions to be graphed. Push the ADD soft button to open up the equation editor and enter the equation. Push ENTER to return to the function list. You can add as many functions to be graphed as you want, just keep pushing add and typing them in. In this example we will be graphing $ Y1(X)=(X+2)^2 $. Your screen should look like this.

Screen capture of function menu

Return to Top

Setting up the Tick Marks

You might be wondering why you would need to adjust the tick marks. A very annoying feature of this calculator is that by default, the ticks correspond to pixels on the screen as opposed to the values of the independent variable. To change these ticks hold LS and press F4. This should open up the “Plot Setup” menu. To change the tick marks to correspond to the independent variable you need to remove the check mark next to “Pixels”. The value of the horizontal and vertical tick marks can be changed by adjusting the values of “H-Tick” and “V-Tick”. The “Plot Setup” menu should now look something like this.

Screen capture of plot setup menu

Return to Top

Setting up the Window

The final step is to set up the dimensions of the window. While holding LS press F2 to open up the “Plot Window” menu. The two values for H-View and the two values for V-View specify the dimensions of the graph. We will want to view the graph from $ -5 \lt X \lt 2 $ and $ -1 \lt Y1(X) \lt 4 $. The “Plot Window” menu should now look like this.

Screen capture of plot window menu

Once this is done we are ready to view the graph. press the ERASE soft button and then the DRAW soft button, and the graph should appear! If you don’t press ERASE, the new graph will be drawn over the previous graph and it will become a big mess. To change the window settings, you must first press CANCEL (which is the same button as the ON button). If you don’t first cancel out of the graph, you won’t be able to switch between the graph menus. The final graph should look like this.

Screen capture of resulting graph for Y1(x)=(x+2)^2

Return to Top

A Few Tricks

There are a few tricks and buttons that took me a while to learn. Sometimes the menu at the bottom of the graph screen takes up too much space or hides a detail you want to see. To make hide/show the menu press either the + or – keys. If you know the range of the independent variable that you want to plot the graph over but are not sure what the resulting values of the function will be, in the “Plot Window” menu you can enter the values for H-View, and then push the AUTO soft key. This will automatically adjust the V-View values to accommodate the function.

Return to Top

MATLAB Beginner’s Guide

This tutorial is meant to help you get started with MATLAB. It assumes you have never used MATLAB and will teach you the very basics of the program. Lets get started.

  1. Basic Calculations
  2. Creating Variables
  3. Using Variables
  4. Tips

Basic Calculations

When you first start up MATLAB your screen should look something like this

Matlab window after startup

For right now we will only be concerned with the “Command Window”. This is the main window at the center of the screen where you will be entering all of your commands. Let’s try to do a very simple calculation to start things off. Type in 2 + 2 (without the quotation marks) into the Command Window and push the ENTER key on your keyboard. I will be using quotation marks to denote input and output from MATLAB. The Enter key is used to run a command. As could be expected, MATLAB spits back 4.

>> 2 + 2
ans =
     4

By default MATLAB likes to spread out the output. To make it print the output more compactly type format compact and push ENTER. As long as vectors and matrices are not used, MATLAB pretty much behaves like a regular calculator. It follows the standard order of operations: parentheses -> exponents and roots -> multiplication and division -> addition and subtraction. An exponent can be entered by using the ^ key. Complicated and long expressions can easily be evaluated. For example:

>> ((10 * 2 - 5)^3)/(100.4 + 8^(1/2))
ans =
   32.6945

It is worth noting that MATLAB ignores spaces, however, I recommend using them to make the input easier to read.

Return to Top

Creating Variables

MATLAB allows the user to create variables. A variable is simply a symbol which can be assigned a value. For example A = 5. Variables in MATLAB do not need to be initialized like in some other programming languages. So, to assign a value to a variable, just enter the variable name followed by an equals sign, and then the value to be stored. Here are some examples:

>> B = 64.2
B =
   64.2000
>> pressure = 99
pressure =
   99

Variables are case-sensitive and can be named anything as long as they satisfy two conditions:

  • The name of a variable can not start with a number.
  • The name of a variable can only consist of letters, numbers, and underscores.

Here are some examples of valid and invalid variable names.

  • a13_13Valid
  • Maximum_VoltageValid
  • 1st_numberInvalid because it starts with a number
  • total_%Invalid because it contains an invalid character “%”
  • a/b Invalid because it contains an invalid character “/”

Expressions can also be assigned to variables. The expression is then evaluated and the resulting number is stored in the variable. For example:

>> A = (6^4 + 1) / 100
A =
   12.9700

As you can see, whenever you run a command MATLAB always prints some kind of output. Sometimes that output is necessary, like the output to an addition problem, but sometimes it just clutters up the workspace. In MATLAB to suppress the output of a command, put a semicolon ; at the end of the line before pushing ENTER. MATLAB will still do whatever you tell it to do, but it will refrain print any output. The use of this will become more apparent when you learn about scripts and functions. Here is an example that shows the difference between including a semicolon or not:

>> A = 5;
>> A = 5
A =
   5

In the case of assigning a value to a variable, the output is unnecessary so it makes the output more readable with the use of a semicolon.

Using Variables

Using variables is very simple. You can treat the variable like any other number when you write your expressions. Any place you can use a number, you can also use a variable. Note that using variables for symbolic (i.e. a + a = 2a) calculations is different and will not work like that. It is possible to do in MATLAB but requires the symbolic toolbox and will not be covered in this article. In the following example I assign the value 5 to the variable A, and then use the variable in an expression.

>> A = 5
A =
     5
>> 5 + A
ans =
    10

As you can see, MATLAB treated the variable A just like the number 5. Multiple variables can also be used in a single expression without issues.

>> A = 5
A =
     5
>> B = 2
B =
     2 
>> (A + 5) * B
ans =
    20

You might have noticed that the output sometimes displays ans = . MATLAB automatically saves the last output of a calculation into the variable ans. This makes it easier to break up calculations into multiple parts and use the answer in a following calculation. Here is an example ans in action:

>> 5 + 5
ans =
    10
>> ans^2
ans =
   100
>> ans - 20
ans =
    80

Tips

There are a few tips that are handy to know when working with MATLAB. If you want to clear all the text from the Command Window, use the command clc. If you want to remove a variable from the program memory, type clear variable_name and push ENTER (replace variable_name with the name of the variable you want to remove). More useful is the command clear all which will remove all the variables from memory. It’s useful for starting over.

Sometimes you want to repeat a previous command. To cycle through the past commands, push the “up-arrow” or “down-arrow” keys on your keyboard when the cursor is in the command line.

By default MATLAB only prints four digits of the output. This makes it easy to read but is sometimes not enough when a high degree of accuracy is required. If you need more digits in the output you can type format long to display up to 15 digits. Type help format in MATLAB to get more info about the different options you have for displaying output. The MATLAB help function is usually pretty useful and is accessed by typing help command_name, where command_name is whatever command you want to get more information about. MATLAB will display the help text right in the Command Window.

That concludes the tutorial. It only covered the most basic MATLAB topics.