Professional Documents
Culture Documents
Alexandria University
Faculty of Engineering
Matlab
Contents
➢Introduction
➢Matrices
▪ Numerical matrixes
➢Elementary Math
▪ Math Functions
➢Graphics Fundamentals
▪ 2D plotting
▪ 3D plotting
▪ Subplots
➢Script Files
➢M-file Programming
➢Flow Control Statements
Abdelrahman Mohamed fargly
3
➢Matlab Simulink
➢Graphical User Interface (GUI)
--------------------------------------------------------------
for any extra information contact math works
Alexandria University
Faculty of Engineering
Introduction
• What is MATLAB?
Installing matlab
• Workspace
▫ view program variables
▫ clear to clear
▫ double click on a variable to see it in the Array Editor
• Command History
▫ view past commands
▫ save a whole session using diary
• Launch Pad
▫ access tools, demos and documentation
Command
History Command Window
Abdelrahman Mohamed Farghly
11
Workspace Interface
⚫ The workspace provides a summary of the
variables
• Changing color:
•
Syntax Errors
⚫ All errors are given in the Command Window in
red
⚫ Nature of error is explained
▪ Clc
▪ clear all
▪ Clear “ variable”
➢X=5 command
➢X=5;
➢who command
➢whos
Compute (2+3-9)*7^2/4
ans
=-49
Example
Arithmetic operation:
» -5/(4.8+5.32)^2
ans =
-0.0488
» (3+4i)*(3-4i)
ans =
25
» cos(pi/2)
ans =
6.1230e-017
» exp( acos(0.3))
ans =
3.5470
Complex number:
» X=3+4i
real(x)
ans =
3
» Imag(x)
ans =
4
» Abs(x)
ans =
5
» Angle(x)
ans =
0.9273
» Conj(x)
Ans =
3-4i
Trigonometric
➢Example:
➢ compute the difference
Sin(pi/2) and Sind(90)
▪ More example :
▪ sin(pi/4) ,Sind(45)
▪ asin(1) and a Sind(1)
▪ Sec (x),cosec(x),cot(x),tan(x),…….ete
Round-off functions
Relational operation
➢ A > B The result is true if A is greater than B, and is false otherwise
➢ A < B The result is true if A is smaller than B, and is false otherwise
• A>=B True if A is greater than or equal to B, false otherwise
• A<=B True if A is smaller than or equal to B, false otherwise
• A==B The result is true is A is equal to B, and is false otherwise
• A~=B The result is true is A is not equal to B, and is false otherwise
• Examples:
• >>a=5;b=2;
• >>x=a>b; %x=1
• >>x=(a~=b) %x=1
• Note:
• Many users confuse the double equality sign (==) used in relational tests with
the equality sign (=) used in assignments. When a user uses (=) instead of (==),
Matlab usually reports that an expected relational operator wasn't found.
Relational operation
Relational operation
Relational operation
Logical operation
Logical operation
Logical operation
Logical operation
Logical operation
General Functions
• who: List current variables
• whos: List current variables in details
• clear x: Clear variable x from memory
• clear all: Clear all variables from memory
• open: opens new file
• figure(n): opens new figure numbered n
• close: closes last figure
• close all: closes all figures
• dir: List files in directory
• format: Set output format
• Help: to know about any command and example
• Lookfor: to search for command
• exit: quits MATLAB
Exercise
• 5 minutes
• x=123;y=234;z=345
• Write the command expression and get the
result:
1) the sum of x and y
2) subtract y from z
3) the multiplication of x and z
• Answer
1) x+y=357;2)z-y=111;3)x*z=42435