Lec 4
Lec 4
“MATLAB”
D r. K h a l e d H a m e d
Lecturer of Mechatronics Engineering
2024
1
Outline
2
Systems of Linear Equations
3
Worked Example: Linear Algebra
• Given a matrix
» mat=[1 2 -3;-3 -1 1;1 -1 1];
• Calculate the rank of a matrix
» r=rank(mat);
➢ the number of linearly independent rows or columns
• Calculate the determinant
» d=det(mat);
➢ mat must be square; matrix invertible if det nonzero
• Get the matrix inverse
» E=inv(mat);
➢ if an equation is of the form A*x=b with A a square matrix,
x=A\b is (mostly) the same as x=inv(A)*b
5
Outline
6
Polynomials
7
Polynomial Operations
9
Exercise: Polynomial Fitting
• Plot the fitted polynomial on the same plot, using the same
x values and a red line
10
Exercise: Fitting Polynomials
11
Nonlinear Root Finding
13
Numerical Differentiation
>> syms x
>> y=sin(x)
>> dydx=diff(y)
14
Numerical Integration
>> syms x
OR
q = int( fun,0,15)
15