atlab course - vgloop.com · -version of java software for the matlab product. the version numbers...
TRANSCRIPT
Matlab Course
Lecture time: Sunday Off
Monday 8:00-10:00 12:00-2:00
Tuesday 14:00-16:00
Wednesday 10:00-12:00 14:00 - 16:00
Thursday 8:00 - 10:00
Location: Albiruni I\II Lab-B Building
Thaer Khatib, Palestine Polytechnic University © 1
Note: The Matlab Software Would be on the Desktop in a file named Matlab _R2008A
For Homework's and any other information
Name| Section| HW#
Thaer Khatib, Palestine Polytechnic University © 2
Matlab (matrix laboratory)
high-performance language for technical computing integrates
computation, visualization, and programming in an easy-to-use
environment where problems and solutions are expressed in
familiar mathematical notation.
Developed by MathWorks.
Thaer Khatib, Palestine Polytechnic University © 3
Matlab (matrix laboratory)
Typical uses for Matlab
Math and computation
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface building
Thaer Khatib, Palestine Polytechnic University © 4
Installation Procedure
Thaer Khatib, Palestine Polytechnic University © 5
6 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
7 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
11111-11111-11111-02626
8 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
9 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
10 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
11 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
12 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
license_standalone.dat
13 Thaer Khatib, Palestine Polytechnic University ©
Installation Procedure
14 Thaer Khatib, Palestine Polytechnic University ©
The Matlab environment
Command Window
Changing current directory
Prompt\Command line
Files and directories Inside the current directory
Command History
15 Thaer Khatib, Palestine Polytechnic University ©
Matlab can be used as calculator
16 Thaer Khatib, Palestine Polytechnic University ©
Our first command
Writing a command in the command line
17 Thaer Khatib, Palestine Polytechnic University ©
Our first Scrip M-File
18 Thaer Khatib, Palestine Polytechnic University ©
Making errors …
19 Thaer Khatib, Palestine Polytechnic University ©
Example
Write a script:
University name
Your name and ID #
Specialization-department-college
Formal email
20 Thaer Khatib, Palestine Polytechnic University ©
Identifiers
21 Thaer Khatib, Palestine Polytechnic University ©
Identifiers
22 Thaer Khatib, Palestine Polytechnic University ©
Reserved words (Keywords)
23 Thaer Khatib, Palestine Polytechnic University ©
Reserved words (Keywords)
Special Variables pi, eps, ….
realmax, realmin, sin, cos, ….
sqrt(i), rem(i,j),…
24 Thaer Khatib, Palestine Polytechnic University ©
Constants
25 Thaer Khatib, Palestine Polytechnic University ©
Variables
26 Thaer Khatib, Palestine Polytechnic University ©
Variables (cont.)
27 Thaer Khatib, Palestine Polytechnic University ©
Variables (cont.)
28 Thaer Khatib, Palestine Polytechnic University ©
Variables (cont.)
29 Thaer Khatib, Palestine Polytechnic University ©
Operations on variables
30 Thaer Khatib, Palestine Polytechnic University ©
List of variables
• Who
31 Thaer Khatib, Palestine Polytechnic University ©
Array is the main data structure
used in Matlab
32 Thaer Khatib, Palestine Polytechnic University ©
Examples of 1D and 2D arrays
33 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
34 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
35 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
36 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
37 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
38 Thaer Khatib, Palestine Polytechnic University ©
Creating 1D Arrays
39 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
40 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
41 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
42 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
43 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
44 Thaer Khatib, Palestine Polytechnic University ©
Indexing 1D Arrays
45 Thaer Khatib, Palestine Polytechnic University ©
Use indexing to edit 1D Arrays
46 Thaer Khatib, Palestine Polytechnic University ©
Use indexing to edit 1D Arrays
47 Thaer Khatib, Palestine Polytechnic University ©
1D Array Orientation
Note: difference btw (’) and (.’)
48 Thaer Khatib, Palestine Polytechnic University ©
49 Thaer Khatib, Palestine Polytechnic University ©
Reminder of previous lecture
• Introduction.
• Matlab installation.
• Matlab interface.
• Identifiers.
• Arrays.
• Indexing.
• Simple operations on arrays.
50 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on 1D arrays
51 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on 1D arrays
52 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on 1D arrays
53 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on 1D arrays
54 Thaer Khatib, Palestine Polytechnic University ©
Sub-array searching
55 Thaer Khatib, Palestine Polytechnic University ©
Sub-array searching
56 Thaer Khatib, Palestine Polytechnic University ©
Sub-array searching
57 Thaer Khatib, Palestine Polytechnic University ©
Arithmetic operations on 1D arrays
58 Thaer Khatib, Palestine Polytechnic University ©
Arithmetic operations on 1D arrays
59 Thaer Khatib, Palestine Polytechnic University ©
Arithmetic operations on 1D arrays
60 Thaer Khatib, Palestine Polytechnic University ©
Arithmetic operations on 1D arrays
61 Thaer Khatib, Palestine Polytechnic University ©
Matrices (2D Array)
62 Thaer Khatib, Palestine Polytechnic University ©
Creating matrices
63 Thaer Khatib, Palestine Polytechnic University ©
Creating matrices
64 Thaer Khatib, Palestine Polytechnic University ©
Creating matrices
65 Thaer Khatib, Palestine Polytechnic University ©
Creating matrices
66 Thaer Khatib, Palestine Polytechnic University ©
Indexing matrices
67 Thaer Khatib, Palestine Polytechnic University ©
Indexing matrices
68 Thaer Khatib, Palestine Polytechnic University ©
Indexing matrices
69 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
70 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
71 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
72 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
73 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
74 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
75 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
76 Thaer Khatib, Palestine Polytechnic University ©
Using indexing to modify matrices
77 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
78 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
79 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
80 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
81 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
82 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
83 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
84 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
85 Thaer Khatib, Palestine Polytechnic University ©
Simple operations on matrices
86 Thaer Khatib, Palestine Polytechnic University ©
87 Thaer Khatib, Palestine Polytechnic University ©
Reminder of previous lecture
• Simple operations on 1D arrays.
• Arithmetic operations on 1D arrays.
• Creating matrices.
• Indexing matrices.
• Simple operations on matrices.
• Arithmetic operations on matrices.
88 Thaer Khatib, Palestine Polytechnic University ©
Plot command
89 Thaer Khatib, Palestine Polytechnic University ©
Plot command
90 Thaer Khatib, Palestine Polytechnic University ©
91 Thaer Khatib, Palestine Polytechnic University ©
Subplot command
The subplot command allows you to subdivide the graphing window into a grid
of m rows and n columns. The function
splits the figure into an m X n matrix. The variable p identifies the portion of the window
where the next plot will be drawn. For example, if the command
92 Thaer Khatib, Palestine Polytechnic University ©
Subplot command
Example:
x=0:0.1:2*pi;
subplot(2,2,1);
plot(x,sin(x));
subplot(2,2,2);
plot(x,cos(x));
subplot(2,2,3)
plot(x,exp(-x));
subplot(2,2,4);
plot(x,sqrt(x))
93 Thaer Khatib, Palestine Polytechnic University ©
Complex numbers
The symbol "i" identifies the imaginary part and has to be typed
immediately after the numerical value of the imaginary part
94 Thaer Khatib, Palestine Polytechnic University ©
Construct complex data from real and imaginary components
complex(x,y)
95 Thaer Khatib, Palestine Polytechnic University ©
real(x), imag(x), abs(x)
96 Thaer Khatib, Palestine Polytechnic University ©
Isreal(x), conj(x)
Determine whether input is real array
Complex conjugate
97 Thaer Khatib, Palestine Polytechnic University ©
Cart2pol, pol2cart
98 Thaer Khatib, Palestine Polytechnic University ©
Cart2pol, pol2cart
99 Thaer Khatib, Palestine Polytechnic University ©
Cart2sph, sph2cart
Transform Cartesian coordinates to spherical
Transform spherical coordinates to Cartesian
cart2sph
sph2cart
100 Thaer Khatib, Palestine Polytechnic University ©
Cart2sph, sph2cart
Transform Cartesian coordinates to spherical
Transform spherical coordinates to Cartesian
cart2sph
sph2cart
101 Thaer Khatib, Palestine Polytechnic University ©
ver command
ver:
A header containing:
-The current MATLAB product family version number.
-license number.
-operating system.
-version of Java software for the MATLAB product.
The version numbers for MATLAB and all other installed
MathWorks products.
102 Thaer Khatib, Palestine Polytechnic University ©
Calculus
The Symbolic Math Toolbox provides functions to do the basic
operations of calculus; differentiation, limits, integration,
summation, and Taylor series expansion.
Differentiation
diff(f)
differentiates f with respect to its symbolic variable (in this case x)
Let’s create a symbolic expression.
103 Thaer Khatib, Palestine Polytechnic University ©
Calculus
104 Thaer Khatib, Palestine Polytechnic University ©
Calculus
Limits
The fundamental idea in calculus is to make calculations on functions
as a Variable “gets close to” or approaches a certain value. Recall that
the definition of the derivative is given by a limit
provided this limit exists. The Symbolic Math Toolbox allows you to
compute the limits of functions in a direct manner
105 Thaer Khatib, Palestine Polytechnic University ©
Calculus
Limits
The fundamental idea in calculus is to make calculations on functions
as a Variable “gets close to” or approaches a certain value. Recall that
the definition of the derivative is given by a limit
provided this limit exists. The Symbolic Math Toolbox allows you to
compute the limits of functions in a direct manner
106 Thaer Khatib, Palestine Polytechnic University ©
Calculus
107 Thaer Khatib, Palestine Polytechnic University ©
Calculus
108 Thaer Khatib, Palestine Polytechnic University ©
Calculus
Integration
109 Thaer Khatib, Palestine Polytechnic University ©
Calculus
110 Thaer Khatib, Palestine Polytechnic University ©
Solving Equation
If S is a symbolic expression, solve(S) attempts to find values of
the symbolic variable in S for which S is zero. For example,
111 Thaer Khatib, Palestine Polytechnic University ©
Solving Equation
This is a symbolic vector whose elements are the two solutions.
If you want to solve for a specific variable, you must specify that
variable as an additional argument. For example, if you want to
solve S for b, use the command
Note that these examples assume equations of the form f(x) = 0. If
you need to solve equations of the form f(x)=q(x) you must use
quoted strings. In particular, the command
112 Thaer Khatib, Palestine Polytechnic University ©
Several Algebraic Equations
113 Thaer Khatib, Palestine Polytechnic University ©
Linear algebra
114 Thaer Khatib, Palestine Polytechnic University ©
Linear algebra
115 Thaer Khatib, Palestine Polytechnic University ©
Linear algebra
116 Thaer Khatib, Palestine Polytechnic University ©
Linear algebra
117 Thaer Khatib, Palestine Polytechnic University ©
Polynomial Roots and Characteristic Polynomial
if p is a row vector containing the coefficients of a polynomial,
roots(p) returns a column vector whose elements are the roots
of the polynomial. If r is a column vector containing the roots
of a polynomial, poly(r) returns a row vector whose elements
are the coefficients of the polynomial.
118 Thaer Khatib, Palestine Polytechnic University ©
Polynomial Roots and Characteristic Polynomial
119 Thaer Khatib, Palestine Polytechnic University ©
Polynomial Roots and Characteristic Polynomial