ffgg

Sunday, 22 September 2013

MATLAB Window Environment and the Base Program (Lesson 2)


Starting MATLAB

On the Windows desktop, the installer usually creates a shortcut icon for starting MATLAB; double-clicking on this icon opens MATLAB desktop.
The MATLAB desktop is an integrated development environment for working with MATLAB suite of toolboxes, directories, and programs. We see in Fig. M1.1 that there are four panels, which represent:
  1. Command Window
  2. Current Directory
  3. Workspace
  4. Command History
A particular window can be activated by clicking anywhere inside its borders.
Fig. M1.1 MATLAB Desktop (version 7.0, release 14)
Desktop layout can be changed by following Desktop --> Desktop Layout from the main menu as shown in Fig. M1.2 (Default option gives Fig. M1.1).
 
Fig. M1.2 Changing Desktop Layout to History and Command Window option

Command Window
We type all our commands in this window at the prompt ( >> ) and press return   to see the results of our operations. Type the command ver on the command prompt to get information about MATLAB version, license number, operating system on which MATLAB is running, JAVA support version, and all installed toolboxes. If MATLAB don't regard to your speed of reading and flush the entire output at once, just type more on before supplying command to see one screen of output at a time. Clicking the What's New button located on the desktop shortcuts toolbar, opens the release notes for release 14 of MATLAB in Help window. These general release notes give you a quick overview of what products have been updated for Release 14.
Working with Command Window allows the user to use MATLAB as a versatile scientific calculator for doing online quick computing. Input information to be processed by the MATLAB commands can be entered in the form of numbers and arrays.
As an example of a simple interactive calculation, suppose that you want to calculate the torque ( T ) acting on 0.1 kg mass ( m ) at   swing of the pendulum of length ( l ) 0.2 m. For small values of swing, T is given by the formula . This can be done in the MATLAB command window by typing:
>>   torque = 0.1*9.8*0.2*pi/6
MATLAB responds to this command by:
torque =
  0.1026
MATLAB calculates and stores the answer in a variable torque (in fact, a   array) as soon as the Enter key is pressed. The variable torque can be used in further calculations.   is predefined in MATLAB; so we can just use pi without declaring it to be 3.14….Command window indicating these operations is shown in Fig. M1.3.


Fig. M1.3 Command Window for quick scientific calculations ( text in colored boxes corresponds to explanatory notes ).
If any statement is followed by a semicolon,
>> m = 0.1;
>> l = 0.2;
>> g = 9.8;
the display of the result is suppressed. The assignment of the variable has been carried out even though the display is suppressed by the semicolon. To view the assignment of a variable, simply type the variable name and hit Enter. For example:
>> torque=m*g*l*pi/6;
>> torque
torque =
   0.1026
It is often the case that your MATLAB sessions will include intermediate calculations whose display is of little interest. Output display management has the added benefit of increasing the execution speed of the calculations, since displaying screen output takes time.
Variable names begin with a letter and are followed by any number of letters or numbers (including underscore). Keep the name length to 31 characters, since MATLAB remembers only the first 31 characters. Generally we do not use extremely long variable names even though they may be legal MATLAB names. Since MATLAB is case sensitive, the variables A and a are different.
When a statement being entered is too long for one line, use three periods, , followed by   to indicate that the statement continues on the next line. For example, the following statements are identical (see Fig. M1.4).
>> x=3-4*j+10/pi+5.678+7.890+2^2-1.89
>> x=3-4*j+10/pi+5.678...
+7.890+2^2-1.89
+ addition,   subtraction, * multiplication, / division, and ^ power are usual arithmetic operators.
The basic MATLAB trigonometric commands are sin, cos, tan, cot, sec and csc. The inverses , etc., are calculated by asin, acos, etc. The same is true for hyperbolic functions. Some of the trigonometric operations are shown in Fig M1.5.
Variables j = and i = are predefined in MATLAB and are used to represent complex numbers.

Fig. M1.4 Command Window with example operations

 Fig. M1.5 Example trigonometric calculations

MATLAB representation of complex number :
  or  
The later case is always interpreted as a complex number, whereas, the former case is a complex number in MATLAB only if j has not been assigned any prior local value.
MATLAB representation of complex number :
  or  
  or  
In Cartesian form, arithmetic additions on complex numbers are as simple as with real numbers. Consider two complex numbers   and . Their sum   is given by
For example, two complex numbers   and   can be added in MATLAB as:
>>   z1=3+4j;  
>>   z2=1.8+2j;
>>   z=z1+z2
z =
   4.8000 + 6.0000i
Multiplication of two or more complex numbers is easier in polar/complex exponential form. Two complex numbers with radial lengths   and   are given with angles   and   rad. We change   to radians to give   rad=   rad. The complex exponential form of their product   is given by
This can be done in MATLAB by:
>>   theta1=(35/180)*pi;
>>   z1=2*exp(theta1*j);
>>   z2=2.5*exp(0.25*pi*j);
>>   z=z1*z2
z =
  0.8682 - 4.9240j
Magnitude and phase of a complex number can be calculated in MATLAB by commands abs and angle. The following MATLAB session shows the magnitude and phase calculation of complex numbers   and .
>> abs(5*exp(0.19*pi*j))
ans =
     5
>>   angle(5*exp(0.19*pi*j))
ans =
    0.5969
>>   abs(1/(2+sqrt(3)*j))
ans =
    0.3780
>>   angle(1/(2+sqrt(3)*j))
ans =
   -0.7137
Some complex numbered calculations are shown in Fig. M1.6.

Fig. M1.6 Example complex numbered calculations  

The mathematical quantities and   are calculated with exp(x), log10(x), and log(x), respectively.
All computations in MATLAB are performed in double precision . The screen output can be displayed in several formats. The default output format contains four digits past the decimal point for nonintegers. This can be changed by using the format command. Remember that the format command affects only how numbers are displayed, not how MATLAB computes or saves them. See how MATLAB prints   in different formats.

Format command at MATLAB prompt
Display format
format short
31.4159
format short e
3.1416e+001
format long
31.41592653589793
format long e
3.141592653589793e+001
format short g
31.416
format long g
31.4159265358979
format bank
31.42
The following exercise will enable the readers to quickly write various mathematical formulas, interpreting error messages, and syntax related issues.
 

Exercise M1.1
  1. By using arbitrary values of , check that .
  2. Verify with a few arbitrary values of   that .
  3. Verify with a few arbitrary values of   that .
  4. For t =0, 2, 5, 7, 12 and 25, find the value of the function .

Exercise M1.2
  1. Try entering complex number   in MATLAB as 3+j4 and check the answer. Initialize   and then enter 3+4j, 3+j*4, and 3+4*j and check the various answers. Interpret messages given by MATLAB.

  2. Calculate magnitude and phase of the following complex numbers for   using MATLAB.

    1.   

    2. .

  3. Use MATLAB to calculate the magnitude and phase of   for



Exercise M1.3
  1. Calculate the quantity   for .
  2. Calculate   for .


Note: Inf, and NaN are predefined in MATLAB. NaN stands for Not-a-Number and results from undefined operations like 0/0. Inf represents .

 

Current Directory Window
This window (Fig. M1.7) shows the directory, and files within the directory which are in use currently in MATLAB session to run or save our program or data. The default directory is ‘C:\MATLAB7\work'. We can change this directory to the desired one by clicking on the square browser button near the pull-down window.
 
Fig. M1.7 Current directory window

One can also use command line options to deal with directory and file related issues. Some useful commands are shown in Table M1.1.
 
Table M1.1
Command
Usage
cd, pwd
To see the current directory
cd ..
To go one directory back from the current directory
cd \
To go back to the root directory
cd dir_name
To change to the directory named dir_name
ls or dir
To see the list of files and subdirectories within the current directory
what
Lists MATLAB-specific files in the directory. MATLAB specific files are with the extensions .m, .mat, .mdl, .mex, and .p.
mkdir (parentdir,dir_name)
mkdir dir_name
Makes new directory with the name dir_name in the parent directory specified by parentdir .
When supplied with only dir_name, it creates new directory within the current directory
delete file_name
delete *.m
 
Deletes file from the current directory.
Deletes all m-files from the current directory.

 

MATLAB desktop snapshot showing selected commands from Table M1.1 are shown in Fig. M1.8.
 

Workspace

Workspace window shows the name, size, bytes occupied, and class of any variable defined in the MATLAB environment. For example in Fig.M1.9, ‘b' is 1 X 4   size array of data type double and thus occupies 32 bytes of memory. Double-clicking on the name of the variable opens the array editor (Fig. M1.10). We can change the format of the data (e.g., from integer to floating point), size of the array (for example,   for variable A, from 3 X 4 array to 4 X 4 array) and can also modify the contents of the array.
 

Fig. M1.8 Example directory related commands


If we right-click on the name of a variable, a menu pops up, which shows various operations for the selected variable, such as: open the array editor, save selected variable for future usage, copy, duplicate, and delete the variable, rename the variable, editing the variable, and various plotting options for the selected variable.

Fig. M1.9 Entries in the Workspace

Fig. M1.10 Array editor window

 

Workspace related commands are listed in Table M1.2.

Table M1.2

Command Usage
who
Lists variables currently in the workspace
whos
Lists more information about each variable including size, bytes stored in the computer, and class type of the variables
clear
Clears the workspace. All variables are removed
clear all
Removes all variables and functions from the workspace. This can also be done by selecting Edit from the main menu bar and then clicking the option Clear Workspace .
clear var1 var2
Removes only var1 and var2 from the workspace.
For example, see the following MATLAB session for the use of who and whos commands.
>> who
Your variables are:
A b
>> whos
Name Size Bytes Class
A 3x4 96 double array
b 1x4 32 double array
Grand total is 16 elements using 128 bytes

Command History Window
This window (Fig. M1.11) contains a record of all the commands that we type in the command window. By double-clicking on any command, we can execute it again. It stores commands from one MATLAB session to another, hierarchically arranged in date and time. Commands remain in the list until they are deleted.

Fig. M1.11 Command history window

Commands can also be recalled with the up-arrow   key. This helps in editing previous commands.
Selecting one or more commands and right-clicking them, pops up a menu, allowing users to perform various operations such as copy, evaluate, or delete, on the selected set of commands. For example, two commands are being deleted in Fig. M1.12. 

Copyrights (c) (NPTEL, IIT) (http://nptel.iitm.ac.in)

MATLAB Window Environment and the Base Program (Lesson 1)


Objectives:
  • Introduction to MATLAB family of programs

  • Brief introduction to MATLAB base program in an interactive "hands on" tutorial style
MATLAB, an abbreviation of MATrix LABoratory, is a high-level technical computing environment suitable for solving scientific and engineering problems. The MATLAB family of programs includes the base program plus a variety of application-specific solutions called toolboxes . Toolboxes are comprehensive collections of MATLAB functions that extend the MATLAB environment to solve particular classes of problems. In this module, the environment provided by the base program is explored.
The MATLAB base program along with the functions from the Control System Toolbox, can be used to analyze and design control systems problems such as those covered in this course. Control System Toolbox includes interactive analysis and design tools called LTI Viewer, and SISO Design Tool. The LTI Viewer uses a Graphical User Interface (GUI) to generate and view time and frequency response plots of Linear Time-Invariant (LTI) transfer functions and obtain measurements from these plots. The SISO Design Tool uses a GUI to provide a convenient and interactive way to design Single-Input-Single-Output (SISO) control systems by the conventional trial-and-error approach. We start using functions of Control System Toolbox in module 2, and enhance its usage in later modules. Whenever MATLAB is referred to in this course, you can interpret that to mean the base program plus the Control System Toolbox. This, in fact, constitutes the beginning of the study of MATLAB for control engineering. There is so much more that must be explored for additional functionality and convenience in designing control systems and analyzing a system's behaviour.
Symbolic Math Toolbox adds symbolic mathematics capability to the MATLAB environment. Functions and equations can be entered symbolically. Symbolic expressions can be manipulated algebraically and simplified. Transfer functions can be entered almost as written. Laplace transforms as well as their inverses can be entered and found in symbolic form. An introduction to Symbolic Math Toolbox and its capabilities will be provided in Module 2.
MATLAB's Simulink software is used to simulate systems. It uses a GUI to interact with blocks that represent subsystems. We can position the blocks, resize the blocks, label the blocks, specify block parameters, and interconnect blocks to form complete systems from which simulations can be run. Simulink will be introduced in Module 3. We will enhance usage of Simulink in later modules to study the effects of nonlinearities, and uncertainties in model parameters on the performance of closed-loop systems.
By its nature, the presentation on MATLAB and its Toolboxes in this course cannot cover all the background and details necessary for a complete understanding of MATLAB. The limited objective of the presentation here is to give enough information to enable the reader to apply MATLAB to the analysis and design problems covered in this book. For further details, the readers are referred to extensive documentation, in both printed and online format, provided by the MathWorks Inc.

Copyrights (c) NPTEL 
(http://nptel.iitm.ac.in/courses/Webcourse-contents/IIT-Delhi/Control%20system%20design%20n%20principles/index.htm)

Saturday, 21 September 2013

Despite Early Criticism, Apple’s iOS 7 Quickly Gains Traction

Samsung Unveils Galaxy Gear Smartwatch

BERLIN — Samsung Electronics unveiled on Wednesday its highly anticipated digital wristwatch that can snap photos, track workouts and use an array of apps — gadgetry that the company hopes will catapult it into a market of smart portable devices that leave cellphones in users’ pockets.

Full Story @ NY Times

Digital Forensics

Modern crime often leaves an electronic trail. Finding and preserving that evidence requires careful methods as well as technical skill

2013-09GarfinkelF6.jpgLaw enforcement can rarely get through a case these days without having to examine some kind of technology. Computers may not be used to commit a particular crime, but they might contain evidence. Similarly, cell phones and other data devices need to be examined regularly. This has led to the development of the field of digital forensics, which examines how equipment has to be handled to ensure that it hasn’t been altered once it has been taken for evidence, how to copy material reliably, and how to maintain equipment that can sometimes erase itself if left unpowered. 

Full Article

NASA's Deep Space Comet Hunter Mission Comes to an End

Sep. 20, 2013 — After almost 9 years in space that included an unprecedented July 4th impact and subsequent flyby of a comet, an additional comet flyby, and the return of approximately 500,000 images of celestial objects, NASA's Deep Impact mission has ended.

Full Story