Matlab Books
1)MATLAB Applications. A Very Useful Software In Computer Engineering and Computer science. It has So Many Application. Must read This Book. Download Link Is Given Below
---------------------------------------------------------------------------------------------------------
Download here
Matlab tutorial.
---------------------------------------------------------------------------------------------------------
Download here
Matlab tutorial.
Tutorial#1
MATLAB WINDOWS:
Once the program starts, the MATLAB desktop window open . The window contains four smaller windows:
· Command Window,
· Workspace Window
· Command History Window
This is the default view that shows four of the various windows of MATLAB. The Start
Button on the lower left side can be used to access MATLAB tools and features.
Command Window:
The command window is MATLAB’s main window and opens when MATLAB is started. It is convenient to have the Command Window as the only visible window, and this can be done by either closing all the other windows (click on the x at the top right-hand side of the window you want to close) or by first selecting the Desktop Layout in the Desktop menu, and then selecting command window Only from the sub-menu that opens.
Work space Window:
The MATLAB® workspace consists of the variables you create and store in memory during a MATLAB session. You add variables to the workspace by using functions, running MATLAB code, and loading saved workspaces. For example, if you run these statements:
A = magic(4);
R = randn(3,4,5);
the workspace includes two variables, A and R.
To open the Workspace browser if it is not currently visible, do either of the following:
Command History Window:
The Command History window displays a log of statements that you ran in the current and previous MATLAB® sessions. The Command History lists the time and date of each session in your operating system's short date format, followed by the statements for that session.Brackets in the left margin indicate commands that are processed as a group. A colored mark precedes each command that generates an error.
Tutorial#2
The use of Command Window
The command Window is MATLAB’s main window and can be used for executing commands, opening other windows, running programs written by the user, and managing the software. An example of theCommand Window.
Notes for working in the Command Window:
To type a command the cursor must be placed next to the command prompt ( >> ).
• Once a command is typed and the Enter key is pressed, the command is executed.
However, only the last command is executed. Everything executed previously (that might be still displayed) is unchanged.
• Several commands can be typed in the same line. This is done by typing a comma
between the commands. When the Enter key is pressed the commands are executed in order from left to right.
• It is not possible to go back to a previous line that is displayed in the Command
Window, make a correction, and then re-execute the command.
• A previously typed command can be recalled to the command prompt with the uparrow key ( on the keyboard). When the command is displayed at the command prompt, it can be modified if needed and then executed.
The semicolon ( ; ):
When a command is typed in the Command Window and the Enter key is pressed, the command is executed. Any output that the command generates is displayed in the Command Window. If a semicolon ( ;) is typed at the end of a command the output of the command is not displayed. Typing a semicolon is useful when the result is obvious or known, or when the output is very large. If several commands are typed in the same line, the output from any of the commands will not be displayed if a semicolon is typed between the commands instead of a comma.
Typing %:
When the symbol % (percent) is typed at the beginning of a line, the line is designated as a comment. This means that when the Enter key is pressed the line is not executed. The % character followed by text(comment) can also be typed after a command (in the same line). This has no effect on the execution of the command. Usually there is no need for comments in the Command Window. Comments,however, are frequently used in a program to add descriptions or to explain the program
The clc command:
The clc command (type clc and press Enter) clears the Command Window. After working in the Command Window for a while, the display may become very long. Once the clc command is executed a clear window is displayed. The command does not change anything that was done before.
Tutorial#3
ARITHMETIC OPERATIONS WITH SCALARS:
Arithmetic operations with scalars, which are numbers. Numbers can be used in arithmetic
calculations directly (as with a calculator) or they can be assigned to variables, which can subsequently be used in calculations. The symbols of arithmetic operation are in table
Operation
|
Symbol
|
Example
|
Addition
|
+
|
5 + 3
|
Subtraction
|
-
|
5 – 3
|
Multiplication
|
*
|
5 * 3
|
Right division
|
/
|
5 / 3
|
Left division
|
\
|
5 \ 3 = 3 / 5
|
Exponentiation
|
^
|
5 ^ 3
|
It should be pointed out here that all the symbols except the left division are the same as in most calculators. For scalars, the left division is the inverse of the right division. The left division, however, is mostly used for operations with arrays.
Order of Precedence:
MATLAB executes the calculations according to the order of precedence displayed below. This order is the same as used in most calculators.
Precedence
|
Mathematical Operation
|
First
|
Parentheses. For nested parentheses, the innermost are executed first.
|
Second
|
Exponentiation.
|
Third
|
Multiplication, division (equal precedence).
|
Fourth
|
Addition and subtraction.
|
In an expression that has several operations, higher-precedence operations are executed before lower-precedence operations. If two or more operations have the same precedence, the expression is executed from left to right. As illustrated in the next section, parentheses can be used to change the order of calculations.
Using MATLAB as a Calculator:
The simplest way to use MATLAB is as a calculator. This is done in the Command Window by typing a mathematical expression and pressing the Enter key. MATLAB calculates the expression and responds by displaying ans =and the numerical result of the expression in the next line.
Tutorial#4
ELEMENTARYMATHBUILT-INFUNCTIONS
In addition to basic arithmetic operations, expressions in MATLAB can include functions. MATLAB has a very large library of built-in functions. A function has a name and an argument in parentheses. For example, the function that calculates the square root of a number is sqrt(x). Its name is sqrt, and the argument is x. When the function is used, the argument can be a number, a variable that has been assigned a numerical value or a computable expression that can be made up of numbers and/or variables. Functions can also be included in arguments, as well as in expressions.
Some commonly used elementary MATLAB mathematical built-in functions are given in Tables . A complete list of functions organized by category can be found in the Help Window.
Functions
|
Description
|
sqrt(x)
|
Square root.
|
nthroot(x,n)
|
Real nth root of a real number x. (If x is negative n must be an odd integer.)
|
exp(x)
|
Exponential of x
|
abs(x)
|
Absolute value
|
log(x)
|
Natural logarithm. Base e logarithm (ln)
|
log10(x)
|
Base 10 logarithm.
|
factorial(x)
|
The factorial function x! (x must be a positive integer.)
|
Trigonometric math functions:
Function
|
Description
|
sin(x)
sind(x)
|
Sine of angle x(x in radians).
Sine of angle x(x in degrees).
|
cos(x)
cosd(x)
|
Cosine of angle x(x in radians).
Cosine of angle x(x in degrees)
|
tan(x)
tand(x)
|
Tangent of angle x(x in radians).
Tangent of angle x(x in degrees).
|
cot(x)
cotd(x)
|
Cotangent of angle x(x in radians).
Cotangent of angle x(x in degrees)
|
The inverse trigonometric functions are asin(x), acos(x), atan(x), acot(x) for the angle in radians; andasind(x), acosd(x), atand(x), acotd(x) for the angle in degrees. The hyperbolic trigonometric functions aresinh(x), cosh(x), tanh(x), and coth(x).
Tutorial#5
DEFINING SCALAR VARIABLES:
A variable is a name made of a letter or a combination of several letters (and digits) that is assigned a numerical value. Once a variable is assigned a numerical value, it can be used in mathematical expressions, in functions, and in any MATLAB statements and commands. A variable is actually a name of a memory location. When a new variable is defined, MATLAB allocates an appropriate memory space where the variable’s assignment is stored. When the variable is used the stored data is used. If the variable is assigned a new value the content of the memory location is replaced.
The Assignment Operator:
In MATLAB the “=” sign is called the assignment operator. The assignment operator assigns a value to a variable.
Variable_name = A numerical value, or a computable expression
The left-hand side of the assignment operator can include only one variable name. The right-hand side can be a number, or a computable expression that can include numbers and/or variables that were previously assigned numerical values. When the Enter key is pressed the numerical value of the right-hand side is assigned to the variable, and MATLAB displays the variable and its assigned value in the next
two lines.
Ø If a semicolon is typed at the end of the command, then when the Enter key is pressed, MATLAB does not display the variable with its assigned value (the variable still exists and is stored in memory).
Ø If a variable already exists, typing the variable’s name and pressing the Enter key will display the variable and its value in the next two lines.
Ø Several assignments can be typed in the same line. The assignments must be separated with a comma (spaces can be added after the comma). When the Enter key is pressed, the assignments are executed from left to right and the variables and their assignments are displayed. A variable is not displayed if a semicolon is typed instead of a comma.
Rules About Variable Names:
A variable can be named according to the following rules:
Ø Must begin with a letter.
Ø Can be up to 63 characters long.
Ø Can contain letters, digits, and the underscore character.
Ø Cannot contain punctuation characters (e.g., period, comma, semicolon).
Ø MATLAB is case sensitive: it distinguishes between uppercase and lowercase letters. For example, AA, Aa, aA, and aa are the names of four different variables.
Ø No spaces are allowed between characters (use the underscore where a space is desired).
Ø Avoid using the name of a built-in function for a variable (i.e., avoid using cos, sin, exp, sqrt, etc.). Once a function name is used to define a variable, the function cannot be used.
Predefined Variables and Keywords:
There are 20 words, called keywords, that are reserved by MATLAB for various purposes and cannot be used as variable names. These words are:
Break case catch classdef continue else elseif end for function global if otherwise parfor
persistent return spmd switch try while
When typed, these words appear in blue. An error message is displayed if the user tries to use a keyword as a variable name. (The keywords can be displayed by typing the command iskeyword.)
USEFUL COMMANDS FOR MANAGING VARIABLES:
The following are commands that can be used to eliminate variables or to obtain information about variables that have been created. When these commands are typed in the Command Window and the Enter key is pressed, either they provide information, or they performa task as specified below.
Command Outcome
Clear Removes all variables from the memory.
clear x y z Removes only variables x, y, and z from the memory.
Who Displays a list of the variables currently in the memory.
whos Displays a list of the variables currently in the memory and their
sizes together with information about their bytes and class
Comments
Post a Comment