Professional Documents
Culture Documents
Mathematical Package: Level 6
Mathematical Package: Level 6
Mathematical Package
MAT 3510
Level 6
1
Mat 3510 Mathematical Packages
Lecture (2)
INTRODUCTION TO MATLAB
2
Mat 3510 Mathematical Packages
What is MATLAB
Once the program starts, the MATLAB desktop window opens (Figure 1-1). The
window contains four smaller windows: the Command Window, the Current Folder
Window, the Workspace Window, and the Command History Window.
Workspace
Command windows
Current Directory
3
Mat 3510 Mathematical Packages
Table 1-1: MATLAB windows
Window Purpose
Command Window Main window, enters variables, runs
programs.
Figure Window Contains output from graphic
commands.
Editor Window Creates and debugs script and
function files.
Help Window Provides help information.
Command History Window Logs commands entered in the
Command Window.
Workspace Window Provides information about the
variables that are used.
Current Folder Window Shows the files in the current folder.
Figure Window: The Figure Window opens automatically when graphics com- mands are
executed, and contains graphs created by these commands. An example of a Figure
Window is shown in Figure 1-2.
Editor Window: The Editor Window is used for writing and editing programs. This window
is opened from the File menu. An example of an Editor Window is shown in Figure 1-3.
4
Mat 3510 Mathematical Packages
Help Window: The Help Window contains help information. This window can be opened
from the Help menu in the toolbar of any MATLAB window. Figure 1-4 shows an open
Help Window.
The Command History Window lists the commands that have been entered in the
Command Window. A command in the Command History Window can be used again in the
Command Window. By double-clicking on the command, the command is reentered in the
Command Window and executed.
5
Mat 3510 Mathematical Packages
When a command is typed in the command window and the Enter Key is pressed, the
command is executed. shown in Figure 1-5.
If a semicolon “;” is typed at the end of a command, the output of the command is
not displayed.
Write “%” at the beginning of a line to write a comment in the program.
Write “…” at the end of a line if you are writing a very long statement and you want
to continue in the next line.
Note:-
- 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.
- The clc command (type clc and press Enter) clears the Command Window.
Athematic Operations
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 (means 53 = 125)
6
Mat 3510 Mathematical Packages
MATLAB as a Calculation
>> 4+5/3+2
5/3 is executed first
ans =
7.6667
>> 27^(1/3)+32^0.2
1/3 is executed first, 27^(1/3) and 32^0.2 are
ans = executed next and + is executed last
5
>> 27^1/3+32^0.2
27^1 and 23^0.2 are executed first, /3 is executed
ans =
next executed next and + is executed last
11
>> 0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5)…
-(0.785)^7/(1*2*3*4*5*6*7) Type three periods … (and press Enter)
ans = to continue the expression on the next line
0.7071
The last expression is the first four terms
𝜋
>> of the Taylor series for sin ( 4 )
MATLAB has a very large library of built-in functions. A function has a name and an
argument in parentheses. For example sqrt(x). Its name is sqrt, and the argument is x.
>> sqrt(64)
Argument is a number
ans =
8
>> sqrt(50+14*5)
Argument is a an expression
ans =
9.5917
7
Mat 3510 Mathematical Packages
>> 54+9*sqrt(100)
Argument includes a function
ans =
12
>>
>> exp(5)
exp(x) Exponential e x . ans =
148.4132
>> abs(-24)
abs(x) Absolute value. ans =
24
>> log(1000)
Natural logarithm. Base e
log(x) ans =
logarithm (ln). 6.9078
>> log10(1000)
log10(x) Base 10 logarithm. ans =
3.0000
8
Mat 3510 Mathematical Packages
The inverse trigonometric functions are asin(x), acos(x), atan(x), acot(x) for the angle
in radians; and asind(x), acosd(x), atand(x), acotd(x) for the angle in degrees. The
hyperbolic trigonometric functions are sinh(x), cosh(x), tanh(x), and coth(x). Table 1-4
uses pi, which is equal to
9
Mat 3510 Mathematical Packages
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.
>> C
The value of the variable C is displayed by
C =
typed the name of the variable.
18
Several assignments can be typed in the same line. See the following example:
a =
12 The variable B is not displayed because a semicolon is
C = typed at the end of the assignment.
18
11
Mat 3510 Mathematical Packages
Pi The number .
eps The smallest difference between two numbers. Equal to 2^(–52).
inf Used for infinity.
i Defined as √ , which is: 0 + 1.0000i.
j Same as i.
NaN Stands for Not-a-Number. Used when MATLAB cannot determine a valid numeric value.
Example: 0/0.
Command Outcome
Example:-
A trigonometric identity is given by:
Verify that the identity is correct by calculating each side of the equation,
substituting
Solution:-
The problem is solved by typing the following commands in the Command Window.
>> RHS=(tan(x)+sin(x))/(2*tan(x))
Calculate the right-hand side.
RHS =
0.9045
11
Mat 3510 Mathematical Packages
Tutorial (1)
1. Calculate:
) 4 √ ) ) 4)
(a) (b) )
4 ) )
)
(c) (d) )
√ ) √ )
(a) (b) √ √ ( ) √
12
Mat 3510 Mathematical Packages
13