Professional Documents
Culture Documents
=
(
(
(
=
(
(
(
=
5
2
1
,
4 3 1
3 2 7
2 6 4
,
9 2 9
7 3 8
0 5 0
C B A
| | | |
| | | |
| | | | | | | | A B B A
A B
B A
+ = +
(
(
(
=
(
(
(
+ + +
+ + +
+ + +
=
(
(
(
+
(
(
(
= +
(
(
(
=
(
(
(
+ + +
+ + +
+ + +
=
(
(
(
+
(
(
(
= +
5 1 10
10 5 15
2 11 4
9 4 ) 2 ( 3 9 1
7 3 3 2 8 7
0 2 5 6 0 4
9 2 9
7 3 8
0 5 0
4 3 1
3 2 7
2 6 4
5 1 10
10 5 15
2 11 4
) 4 ( 9 3 2 1 9
3 7 2 3 7 8
) 2 ( 0 6 5 4 0
4 3 1
3 2 7
2 6 4
9 2 9
7 3 8
0 5 0
| | | |
( ) ( )
( ) ( )
( ) ( ) ( ) ( ) ( )
| | | |
( ) ( ) ( ) ( )
( )
( ) ( ) ( ) ( )
| | | | | | | | A B B A
A B
B A
=
(
(
(
=
(
(
(
+ + + + + +
+ + + + + +
+ + + + + +
=
(
(
(
(
(
(
=
(
(
(
=
(
(
(
+ + + + + +
+ + + + + +
+ + + + + +
=
(
(
(
(
(
(
=
15 22 12
41 35 43
24 42 30
9 4 7 3 0 1 2 4 3 3 5 1 9 4 8 3 0 1
9 3 7 2 0 7 2 3 3 2 5 7 9 3 8 2 0 7
9 2 7 6 0 4 2 2 3 6 5 4 9 2 8 6 0 4
9 2 9
7 3 8
0 5 0
4 3 1
3 2 7
2 6 4
60 77 31
35 75 60
15 10 35
4 9 3 2 2 9 3 9 2 2 6 9 1 9 7 2 4 9
4 7 3 3 2 8 3 7 2 3 6 8 1 7 7 3 4 8
4 0 3 5 2 0 3 0 2 5 6 0 1 0 7 5 4 0
4 3 1
3 2 7
2 6 4
9 2 9
7 3 8
0 5 0
Matrix Operations 2/5
Matrix multiplication can also be considered as linear equations.
The transpose of any matrix switches the column with row
The determinant a matrix
| | | | | |
| | | | | |
( )
( )
( ) ( ) (
(
(
=
(
(
(
+ +
+ +
+ +
=
(
(
(
(
(
(
= =
= + +
= + +
= + +
(
(
(
=
(
(
(
(
(
(
= =
32
33
10
5 9 2 2 1 9
5 7 2 3 1 8
5 0 2 5 1 0
5
2
1
9 2 9
7 3 8
0 5 0
3 3 33 2 32 1 31
2 3 23 2 22 1 21
1 3 13 2 12 1 11
3
2
1
3
2
1
33 32 31
23 22 21
13 12 11
C A D
D C A C A C A
D C A C A C A
D C A C A C A
D
D
D
C
C
C
A A A
A A A
A A A
C A D
( ) ( ) ( )
( ) ( ) ( ) ( ) ( ) 45 3 9 2 8 0 7 9 9 8 5 7 2 9 3 0
9 2 9
7 3 8
0 5 0
22 31 32 21 13 23 31 33 21 12 23 32 33 22 11
33 32 31
23 22 21
13 12 11
= + =
(
(
(
=
+ =
(
(
(
=
A
A A A A A A A A A A A A A A A
A A A
A A A
A A A
A
| |
(
(
(
=
(
(
(
=
(
(
(
=
(
(
(
=
9 7 0
2 3 5
9 8 0
9 2 9
7 3 8
0 5 0
33 23 13
32 22 12
31 21 11
33 32 31
23 22 21
13 12 11
T T
T
A A A
A A A
A A A
A A A
A A A
A A A
A
Matrix Operations 3/5
The inverse of the A matrix:
Find the determinant of the matrix
Find the transpose of the matrix
Find the cofactors of the matrix
Insert the cofactors into the matrix
| |
| |
(
(
(
=
(
(
(
(
(
(
(
(
= = =
=
= = = =
= =
= =
=
=
8889 . 0 1 9556 . 0
0 0 2 . 0
7778 . 0 1 9111 . 0
40
3 5
8 0
1
45
45
2 5
9 0
1
1
45
43
2 3
9 8
1
0
7 0
8 0
1
1 0
9 0
9 0
1
45
9
9 7
9 8
1
1
45
35
7 0
3 5
1
45
45
9 0
2 5
1
1
45
41
9 7
2 3
1
1
1
33
1
32
1
31
1
23
1
22
1
21
1
13
1
12
1
11
1
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
A
Matrix Operations 4/5
To create a matrix inside MATLAB:
Brackets []
Space or comma , , indicates a new column
A semicolon ; indicates a new row
Follow the directions inside example 15.4 (pg. 422-423)
Add Matrices (A+B)
Subtract Matrices (A-B)
Multiply Matrices (A*B)
Find the determinant of a Matrix (det(A))
Follow the directions inside example 15.5 (pg. 424)
Solve a set of linear equations
Gauss elimination (A\B)
Inverse of a matrix (A
-1
=inv(A))
A\B=inv(A)*B
Matrix Operations 5/5
Element by element operation:
In the MATLAB command window type: a.*b
| | | |
| | | |
( )
( ) (
(
(
=
(
(
(
=
(
(
(
(
(
(
=
(
(
(
=
(
(
(
(
(
(
=
36 6 9
21 6 56
0 30 0
4 9 3 2 1 9
3 7 2 3 7 8
2 0 6 5 4 0
4 3 1
3 2 7
2 6 4
.
9 2 9
7 3 8
0 5 0
.
. .
33 33 32 32 31 31
23 23 22 22 21 21
13 13 12 12 11 11
33 32 31
23 22 21
13 12 11
33 32 31
23 22 21
13 12 11
B A
B A B A B A
B A B A B A
B A B A B A
B B B
B B B
B B B
A A A
A A A
A A A
B A
Format
Display Functions:
format:
Allows you to display values in certain ways.
disp:
Used to display text or values. Rarely used, often you can just type in the
variable name, but disp will leave off the name.
fprintf:
Also a display command that allows you to print text and/or values with a
desired number of digits. \n and \t are line breaks and tabs, respectively.
Example 15.1 (pg 404)
Uses the fprintf function to display formatted information to the screen
The %g term is a more compact form of exponential notation, insignificant
zeros do not print
%s is for character strings, \\ is a backslash
For more information on fprintf commands, properties, etc. go to
MATLAB help and type the fprintf
Using Help
How to launch help:
Three ways:
Press the F1 key on the keyboard, a window will appear. On the bottom
left corner of that window select the Open Help Browser.
Using Help
On the menu bar Select Help> Product Help
Instead of typing a function name in the help browser a faster way to
determine what the function does is to do the following:
Highlight the function>Right click the highlighted text>select Help
on Selection.
Using Help
Save
If there are many variables in the directory, rather than retyping them, they can be
saved for a later time in a data file.
The data file is similar to a *.dat file format but using MATLABs format called
a *.mat.
To save the variable workspace:
File>Save Workspace As> Type in filename: practicum_lab_001>select the
create new file folder icon > type: Practicum_lab in the popup window
Double click the new folder created.
Save
Change the current directory:
Below the menu bar select the button
Click the + (plus sign) next to MATLAB, and select the Practicum _lab folder
Press the OK button
Save
To create a m-file:
File> New>M-file
Save
Example of a function inside MATLAB
In the command window:
Type why
Now type open why
USING BASIC MATLAB
FUNCTIONS
Basic MATLAB functions
All of the functions (name, description, examples) in MATLAB can be found
using help
Anyone using MATLAB uses this resources constantly
In the handout go to page 409-410 and look at table 15.7 and 15.8
Shows some basic MATLAB functions
Do example 15.2 in pg 409
Most trigonometric functions in MATLAB are in radians
Radian trigonometric functions:
sin, cos, tan, atan, atan2
Degree trigonometric functions:
sind, cosd, tand, atand
Less number of degree trig functions
Conversion from radians to degree
rad2deg(angle in)
Conversion from degree to radians
deg2rad(angle in)
Basic MATLAB functions
Logical operators:
Table 15.10 and 15.11 pg 412,
If statements use logical operators to determine if something is true/false
Example of a simple if statement
if test
statement
end
Example of a if/else statement
if test
statement
else
statement
end
Example of a if/elseif/else statement
if test
statement
elseif test
statement
else
statement
end
PLOTTING WITH MATLAB
Plotting with MATLAB
Go to pg 414, look at Example 15.3
Optimization problem:
How to determine the maximum volume of a sheet of paper square cuts at
every corner by x centimeters
This can easily be solved using calculus by taking the differentiation of volume
with respect to x and making it equal to zero
Now plug the values into the volume equation, and the cut size will be where
the volume is at maximum
Also looking at the volume equation, the larger of the two x values (5 cm)
will make the volume zero, or at least smaller
( ) ( ) ( ) x x x x x V = =
2
2 10 2 10 2 10
( ) ( ) { }
( ) ( )
6667 . 1 , 0 . 5
12 2
100 12 4 80 80
100 80 12 2 10 4 2 10 0
2
2 2
=
=
+ = + = =
x
x x x x x
dx
V d
( )
( )
6667 . 1
0741 . 74 6667 . 1 6667 . 1 2 10
0 0 . 5 0 . 5 2 10
max
2
2
2
1
max
=
|
|
.
|
\
|
= =
= =
=
cut
x
V
V
V
Plotting with MATLAB
Do Example 15.3 (pg 414)
When finished play around with the plot and line styles
Go on the help browser and type plot in keyword search
This will have links to other functions, and line styles
Line styles=Can be found in help (LineSpec, or Table 15.12 (pg. 416))
Look up some other types of plot anotation like legend, grid, zooming (axis
command), x-y-z labels, titles, 3d plots, 3d mesh plots, 3d surface plots, text
properties which use the TEX commands which can have greek alphabet, symbols,
etc.
Try some of the demos found in help
Best way to learn MATLAB is from the help browser, and by actually using it.