A blog to help electrical engineers and students to learn electrical engineering topics. Basic Electrical Engineering, Power Systems, Electrical Machines, tec.. Now special course on MATLAB for Beginners.



Friday, January 29, 2016

MATLAB - Variables and Operators


Like most programming languages, MATLAB allows you to create variables, and assign values to them. Variables are used to represent all data types including scalars, arrays, matrices and strings. MATLAB variables are created with an assignment statement, which creates the “variable” and assigns to it the value of the “expression” on the right hand side. 
The syntax is
variable name = a value or an expression
For example,
>> x = 5
>> y = 2*x+4 (expression can be a combination of numerical values, mathematical operators, variables, and functions).

Variable Name

A variable name should begin with a letter but may be followed by any combination of letters, digits or underscores (don’t use space or punctuation marks). MATLAB is case (upper and lower case) sensitive (upper and lowercase letters are not interchangeable).  In other words, student, Student, and STUDENT are three distinct variables.  It is useful to keep all your writing in lower case to avoid errors associated with case sensitivity.
Variables in MATLAB can have any names except keywords, MATLAB built-in function names (cos,sin, exp, sqrt, etc.) and special variables. It is a good practice to use variable names that describe the quantity they represent. Once a function name is used to define a variable, the function cannot be used. There are 20 words, called keywords, which are reserved by MATLAB for various purposes and cannot be used as variable names. (iskeyword command will display the list of al keywords.)

Special Variables

ans       A variable that has the value of the last expression that was not assigned to a specific variable
Pi         3.14159265…
i           Imaginary unit,            √-1
j           Same as i
eps       Floating-point relative precision, 2
realmin Smallest floating-point number, 2
realmax Largest floating-point number, (2-e)2
Inf       Infinity
NaN    Not-a-number

Syntax Error

The proper form of a Matlab statement is its syntax. A violation of the form is called a syntax error. Matlab's commands must be typed correctly. If they are not, then an error message is given:
>> 1 = x
??? 1 = x
Error: The expression to the left of the equals sign is not a valid target for an assignment.
>> 3uˆ2
??? 3u^2
Error: Missing operator, comma, or semicolon.
Matlab is trying to tell the user what is wrong.  The first example is violation of assignment statement. Putting a constant on the left side of an equals sign does not fit the meaning of the assignment statement, and it is not allowed. In the second example the error is a missing multiplication operator *.

Commands on Variables

There are commands that can be used to eliminate variables or to obtain information about variables that have been created. You can type who to see a summary of the names of your currently defined variables. The whos command displays a list of the variables currently in the memory and their sizes together with information about their bytes and class. The command whos shows information about all defined variables, but it does not show the values of the variables. To see the value of a variable, simply type the name of the variable and press ENTER or RETURN. To clear all defined variables, type clear or clear all. You can also type, for example, clear x y to clear only x and y.

Change the Display Format

The default format for displaying the numerical values in Matlab is using the four decimal values. The user can change the format in which Matlab displays output on the screen. The format command is used to change the display format. The two main formats are short and long. Short is the format with four decimal points. The long format shows the values with 15 decimal values.


Expressions use familiar arithmetic operators and precedence rules.
+          Addition
-           Subtraction
*          Multiplication
/           Division
\           Left division (mostly used for operations with arrays, we will discuss it with another post)
^          Power 
'           Complex conjugate transpose
( )         Specify evaluation order

Precedence of Operators

All operators in MATLAB are ranked according to their precedence.  Exponentiation has the highest precedence, followed by multiplication and division, and finally addition and subtraction.  Operations are evaluated from left to right.  Parenthesis can be used to over-ride these usual rules of precedence.
1.      ( )         Parentheses  (For nested parentheses, the innermost are executed first.)
2.      ^          Exponentiation
3.      * /        Multiplication & Division
4.      + -        Addition and Subtraction


>> a = 5+4/2
a =
>> b = (2+5)/2
b =
>> c= 4+5/3+2
c =
>> d = 5^3/2
d =
>> e = 27^(1/3)+32^0.2
e =

Other MATLAB Symbols

>>        prompt
. . .       continue statement on next line
,           separate statements and data
%         start comment which ends at end of line
;           (1)        suppress output
            (2)        used as a row separator in a matrix
:           specify range

Relational Operators

Less Than                                <
            Less Than or Equal                 <=
            Greater Than                           >
            Greater Than or Equal             >=
            Equal To                                              ==
            Not Equal To                          ~=

Logical Operators

not                   ~          % highest precedence
and                  &         % equal precedence with or
or                     |          % equal precedence with and


MATLAB An Introduction with Applications, Amos Gilat, JOHN WILEY & SONS, INC.

Friday, January 22, 2016

Familiarize MATLAB Work Environment

(Figure courtesy: https://www.cs.uic.edu/~jbell/CourseNotes/Matlab/Introduction.html)
Figure 1. A typical MATLAB Desktop

The MATLAB Work Environment or MATALB Desktop is the main Matlab application window. It has four sub-windows – Command window, Command history, Workspace and Current Directory as shown in the Figure 1. A Start button is provided on the lower left side, which is used to access MATLAB tools and features. Mathworks made some big changes in the work environment in its latest release 2015b. A screen shot of the latest MATLAB Desktop is shown in Figure 2.

(Figure courtesy: https://www.cs.uic.edu/~jbell/CourseNotes/Matlab/Introduction.html)
Figure 2. A new view of MATLAB Desktop
 Command Window:
The Command Window is where you type in Matlab commands and expressions at the prompt (») and where the output of your command will be displayed. Command window is used to
  • Execute commands
  • Open the windows
  • Run the programs
  • Manage the MATLAB software

Figure 3. Command Window
Workspace Browser:
The Workspace shows the list of variables that are currently defined in a work session, and other information about the variables (type, size , value, etc.). It keeps track of variables you have defined as you execute the commands.
·         Note: If any of the variables in the Workspace are plottable, they may be plotted quickly and easily by right-clicking on the variable name and selecting a plot type.
·         Double click on a variable in the Browser and the Array Editor gets launched, which can be used to obtain information and sometimes edit properties of the variable.
Current Directory:
The Current Directory window, as its name suggests, displays the contents of the current working directory.
  • Double click on any file to open it.
  • Right-click on Matlab scripts and function files to execute the commands contained therein.
  • Right-click on data files to import the data as Matlab variables.

Current directory can be changed by clicking on folders or use the Current Working Directory text box at the top of the Matlab working environment.
Command History:
The Command History window contains a list of commands a user has entered recently in the Command Window, including both current and previous Matlab sessions.
·         To execute a command in command history, double click on the command
·         A command can be dragged to the command window and modified before execute again
·         The entries in the command history can be removed by selecting the command and press ‘Delete’
·         To delete entire command history, Right click and select Clear Command history.
·         These windows may be re-arranged according to your personal preferences, including dragging windows away from the Matlab work environment. In addition to these sub windows there are other special windows used to for special purposes.
Figure Window:
Figure window is shown only when the user displays a graphic. It is automatically opened after any command that draws a figure. Any additional figures you create will overwrite the figure unless you specifically command to open a new Figure window. A sample figure window is shown in figure 4.

Figure 4. Figure Window
Editor Window:
The Editor Window is the window used for writing and editing MATLAB programs. This window can be opened from command window by ‘edit’ command of from the Menu, by selecting File --- New --- mFile (Script). An example of an Editor Window is shown in Figure 5.

Figure 5. Editor Window
Help Window:
The Help Window contains help information. This window can be opened from the Help menu in the toolbar of any MATLAB window. The Help Window is interactive and can be used to obtain information on any feature of MATLAB. 

Tuesday, January 19, 2016

Capacitor - an Introduction

The ability to store energy in the form of electric charge is called capacitance. A device designed to possess capacitance is called a capacitor. A capacitor is a two terminal device used to store energy in the form of electric field. The symbol used to represent capacitance is C. A  capacitor in its simplest form a capacitor is nothing more than two conducting plates separated by a sheet of insulator. In capacitors the conductors are called plates and the insulator is called a dielectric. The larger the surface area of the "plates" (conductors) and the narrower the gap between them, the greater the capacitance is.

Basic Capacitor Action

A capacitor stores energy when an electric charge is forced onto its plates by some other energy source, such as a battery. When there is a potential difference across the terminals, i.e. when the capacitor is connected across a battery as shown in figure below, an electric field develops across the dielectric, causing positive charge +Q to collect on one plate and negative charge −Q to collect on the other plate. These charges on the plates of the capacitor represent a voltage source just as the charges on the plates of a cell do. Note that in the process of charging the capacitor, no electrons move from one plate to the other plate through the dielectric.

Because of opposing voltages, the current stops once the capacitor is charged. The opposite charges on the plates of the capacitor create a new energy source. The energy stored in the capacitor produces a voltage equal to that of the battery. Since the capacitors voltage is equal to, and in opposition to, the battery voltage , a state of equilibrium exists. No current can flow in either direction.

A charged capacitor can be disconnected from the original energy- source (the battery and used as a new energy source. If a voltmeter is connected to the capacitor, it will register a voltage., if a resistor is connected to the capacitor as shown in figure current will flow through the resistor. However, a capacitor has limited use as a primary energy source for two reasons:
  1. For its weight and size, the amount of energy it can store is small compared with what a battery can store.
  2. The voltage available from the capacitor rapidly diminishes as energy is removed from the capacitor
Although the amount of energy stored in a capacitor is small, capacitor can deliver a shock. The shock can be very severe (even fatal) if the capacitor is large and charged to a high voltage.


Capacitance of a capacitor is defined as the ratio of charge Q on each conductor to the voltage V between them.
                        C = Q / V

Unit of Capacitance

The base unit of capacitance is the Farad. The abbreviation for farad is F. One farad is that amount of capacitance which stores 1 C of charge when the capacitor is charged to 1V . In other words, a farad is a coulomb per volt  (C / V).

Question: What is the capacitance of a capacitor that requires 0.5 C to charge it to 25 V?

Given :           Charge (Q) = 0.5 C
                        Voltage (V) = 25V
Solution :       C = Q/V = 0.5/25 = 0.02

Answer :        The capacitance is 0.02 F.

The 0.02 F calculated above is a very high value of capacitance. In most circuits the capacitance used is much lower. In fact, they are usually so much lower that the base unit of farad is too high to conveniently express their value. The micro-farad (10-6) and the picofarad (pF)(10-12) are more convenient units. Both are used extensively in specifying values of capacitors in electronic circuits. Often it is necessary to convert from one unit to another.
            1000 pF = 1000 x 10-6 mF = 0.001 mF
0.001 mF = 0.001 x 106 pF     = 1000 pF

Saturday, January 16, 2016

Anatomy of a Technical Drawing

Different types of electrical drawings are discussed here. Now we will check what are the main parts of a technical drawing. A generic engineering drawing (Blueprint) can be divided into the following five major areas or parts.
  1. Title block
  2. Grid system
  3. Revision block
  4. Notes and legends
  5. Engineering drawing (graphic portion)
The first four parts listed above provide important information about the actual drawing. The ability to understand the information contained in these areas is as important as being able to read the drawing itself. Failure to understand these areas can result in improper use or the misinterpretation of the drawing.

The Title Block

The title block of a drawing, usually located on the bottom or lower right hand corner, contains all the information necessary to identify the drawing and to verify its validity. A title block is divided into several areas as illustrated by Figure 1.

                                                                      Figure 1 Title Block

First Area of the Title Block

The first area of the title block contains the drawing title, the drawing number, and lists the location, the site, or the vendor. The drawing title and the drawing number are used for identification and filing purposes. Usually the number is unique to the drawing and is comprised of a code that contains information about the drawing such as the site, system, and type of drawing. The drawing number may also contain information such as the sheet number, if the drawing is part of a series, or it may contain the revision level. Drawings are usually filed by their drawing number because the drawing title may be common to several prints or series of prints.

Second Area of the Title Block

The second area of the title block contains the signatures and approval dates, which provide information as to when and by whom the component/system was designed and when and by whom the drawing was drafted and verified for final approval. This information can be invaluable in locating further data on the system/component design or operation. These names can also help in the resolution of a discrepancy between the drawing and another source of information.

Third Area of the Title Block

The third area of the title block is the reference block. The reference block lists other drawings that are related to the system/component, or it can list all the other drawings that are cross-referenced on the drawing, depending on the site's or vendor's conventions. The reference block can be extremely helpful in tracing down additional information on the system or component.

Other information may also be contained in the title block and will vary from site to site and vendor to vendor. Some examples are contract numbers and drawing scale.

Grid System

Because drawings tend to be large and complex, finding a specific point or piece of equipment on a drawing can be quite difficult. This is especially true when one wire or pipe run is continued on a second drawing. To help locate a specific point on a referenced print, most drawings, especially Piping and Instrument Drawings (P&ID) and electrical schematic drawings, have a grid system. The grid can consist of letters, numbers, or both that run horizontally and vertically around the drawing as illustrated on Figure 2. Like a city map, the drawing is divided into smaller blocks, each having a unique two letters or number identifier. For example, when a pipe is continued from one drawing to another, not only is the second drawing referenced on the first drawing, but so are the grid coordinates locating the continued pipe. Therefore the search for the pipe contained in the block is much easier than searching the whole drawing.

Figure 2. Example of a Grid

Revision Block

As changes to a component or system are made, the drawings depicting the component or system must be redrafted and reissued. When a drawing is first issued, it is called revision zero, and the revision block is empty. As each revision is made to the drawing, an entry is placed in the revision block. This entry will provide the revision number, a title or summary of the revision, and the date of the revision. The revision number may also appear at the end of the drawing number or in its own separate block. As the component or system is modified, and the drawing is updated to reflect the changes, the revision number is increased by one, and the revision number in the revision block is changed to indicate the new revision number. For example, if a Revision 2 drawing is modified, the new drawing showing the latest modifications will have the same drawing number, but its revision level will be increased to 3. The old Revision 2 drawing will be filed and maintained in the filing system for historical purposes.

Figure 3. Revision Block


There are two common methods of indicating where a revision has changed a drawing that contains a system diagram. The first is the cloud method, where each change is enclosed by a hand-drawn cloud shape, as shown in Figure 4. The second method involves placing a circle (or triangle or other shape) with the revision number next to each effected portion of the drawing, as shown in Figure 4. The cloud method indicates changes from the most recent revision only, whereas the second method indicates all revisions to the drawing because all of the previous revision circles remain on the drawing.
Figure 4. Methods of Denoting Changes

The revision number and revision block are especially useful in researching the evolution of a specific system or component through the comparison of the various revisions.

Notes and Legend

Drawings are comprised of symbols and lines that represent components or systems. Although a majority of the symbols and lines are self-explanatory or standard (as described in later modules), a few unique symbols and conventions must be explained for each drawing. The notes and legends section of a drawing lists and explains any special symbols and conventions used on the drawing, as illustrated on Figure 5. Also listed in the notes section is any information the designer or draftsman felt was necessary to correctly use or understand the drawing. Because of the importance of understanding all of the symbols and conventions used on a drawing, the notes and legend section must be reviewed before reading a drawing.

Figure 5. Notes and Legends

Thursday, January 14, 2016

Basic Electricity Quiz 1

1. Resistance of a material not depending on
    one of these

2. The resistance between the opposite faces of a meter cube of a material is called
    Temperature coefficient
    one of these

3. Which of the following is not a characteristic of a parallel circuit?
    Branch currents are additive
    owers are additive
    onductances are additive
    oltages are additive

4. Voltage across a short circuit will be
    one of these


5. Two resistors of 10 ohm each are connected in series across a 10 V supply. What will be voltage across each resistors


6. Which of the following material has nearly zero temperature coefficient


7. Which of the following statement is true both for a series and parallel dc circuit?
    Branch currents are additive
    owers are additive
    onductances are additive
    oltages are additive


8. A coil has a resistance of 100 ohm at 900C and at 1000C resistance is 101 ohm. The temperature coefficient of the wire at 900C is


9. You have to replace a 1500-ohm in a circuit. But have no 1500-ohm resistor but have several 1000 ohms, which you would connect?
    Three in parallel
    hree in series
    wo in parallel
    wo in parallel and one series

10. Two wires A and B have same cross-section made of same material. Ra = 600 ohm, Rb = 100 ohm. The number of times A is longer than B is

11. Three 10 ohm resistors are connected in delta. If this is transformed to a star what will be the resistance of each branch?
    10 Ohm
    10/2 Ohm
    10/3 Ohm
    30 Ohm


12. Kirchhoff’s current law is applicable to only     Closed loops in network
    Junctions in a network
    Electronic circuits
    Electric circuits

13. KVL is concerned with
    IR drops
    Battery emf
    unction volt
    oth A & B

14. The algebraic sign of an IR drop is primarily dependent on the
    Amount of current flowing through it
    Value of R
    Direction of flow of current
    Battery connection

15. The following formula is used to calculate the total resistance R of a parallel circuit?

16. What is the formula for Ohm’s law?


17.The resistance of a wire will double if we double the

18. A voltage of 100 V is applied to a circuit of resistance of 10 ohms, the power the dissipated by the resistance will be
    100 Watts
    500  Watts
    1000 Watts
    1500 Watts


19. Power taken by a resistance of 20 ohms with a flow of 10 A current is

20. When the high resistance is connected in parallel with a low resistance, the combined resistance is
    igher than the lower resistance
    ower than the higher resistance
    etween the value of high and low resistance
    ess than the lower resistance