Matlab Tutorial 5: Linear Equations
Let us solve a couple examples with Matlab.
Example 3
Let us solve the following example. We have a matrix A=[1 2 3; 4 5 6; 7 8 7]. Find the corresponding eigenvalues!
b= A= 8 3 -2 4 -5 5 8 -6 -17 9 -2 7 |
Now let us find the eigenvectors to the matrix.
>> X=inv(A)*b |
We can find the eigenvectors as columns in matrix X.This means that the matrix A can be diagonalized (linear algebra). We can express the relation as: A=X*D*X-1 or D=X-1*A*X. Maybe you remember the following from the subject in linear algebra. The determinant of the matrix A is the product of the eigenvalues. Check it if you like: det(A) and prod(A)!
Let us see if we can find 3 linear independent eigenvalues in our example. This means that the system can be diagonalized. It also means that the matrix A is invertible and that the 3 vectors span a volume in the space R3. Investigate the matrix A.
>> X=A\b |
Are the rows and columns linearly independent ? What are the eigenvalues for A ?
det(A): Calculates the determinant for the matrix A.
rank(A): Gives how many linearly independent rows and columns there are in matrix A. If all rows and columns are independent this implies that A are invertible.
inv(A): Inverts the matrix A. If A is invertible than det(A) is nonzero.
trace(A): The sum of the diagonal elements in A or the sum of its eigenvalues.
System of differential equations
In an ordinary differential equation we often have a time-dependent variable like x(t). Here we know that the time derivative or growth (velocity) x'(t) depends on x(t). Sometimes we have several such differential equations linked to each other, for instance as below:
x1‘(t)=a11x1(t) + a12x2(t) + …………+ a1nxn(t)
x2‘(t)=a21x1(t) + a22x2(t) + …………+ a2nxn(t)
.
.
.xn‘(t)=an1x1(t) + an2x2(t) + ………….+ annxn(t)
This is a nxn-system. We have n first order differential equations, where aij are the coefficients. A differential equation x'(t)=ax(t) has a general solution according to single variable calculus: x(t)=Ceat
Thus n differential equations will give n similar solutions, where a is the eigenvalue to the equations and this can be real or complex conjugated. The solutions we get from the equation system above are a combination of exponential factors multiplied with constants or (if we have complex eigenvalues) exponential factors multiplied with sine or cosine and of course also some constant.