Professional Documents
Culture Documents
AASTU
AASTU, Adem G.
Matrices and Matrix Computations
MATLAB treats all variables as matrices
Matrices are assigned to expressions with an ’=’ sign
Example: To create: 1 2 3
A 4 5 6
7 8 9
Enter the following:
>> A= [1 -2 3;-4 5 6; 7 8 -9]
x=a: step: b
Examples:
>> x=0:2:10
x=
0 2 4 6 8 10
>> y=10:-2:1
y=
10 8 6 4 2
February 2021 AASTU, Adem G.
Some special matrices generated by
built-in functions
det(A) - determinant
eig(A) - eigenvalues & eigenvectors
inv(A) - inverse
rank - rank
lu - LU decomposition
qr - QR factorization
1. Transpose
2. Scalar Multiplication
3. Addition (Component by component)
4. Multiplication
5. Division
6. Power
7. Component by component Multiplication,
Division and Power
February 2021 AASTU, Adem G.
Polynomials
1. disp
disp(A) displays the array, without printing the
name
If A is a string, the text is displayed
Example:
>> disp('Newton Interpolation Formula')
Newton Interpolation Formula
2. fprintf
(‘filename’,’format’,list)
where file name is optional
format=format control string containing
conversion specifications or any optional text
conversion specifications control the output of
array elements.
multiple arguments
For example,
>> [U, D]=eig(A)
generates a matrix U whose columns are
eigenvctors of A & a diagonal matrix D
with the eigenvalues of on its diagonal.
Example: p = [1 3 -4 5]
ans =
0.2500 1.0000 -2.0000 5.0000 0.0000
AASTU, Adem G. 28
Fzero
To find a zero of fun near x0, if x0 is a scalar, we use
fzero((@fun, x0 )
AASTU, Adem G. 29
Example 1: Calculate π by finding the zero of the sine
function near 3.
>> fzero(@sin,3)
ans = 3.1416
Example 2: To find the zero of cosine between 1 and 2
>> fzero(@cos,[1 2])
ans = 1.5708
Note that cos(1) and cos(2) differ in sign.
AASTU, Adem G. 30
Example 3
Thank you!