Matrix Functions in Matlab- Matlab tutorials

Matlab Functions
Once you are able to create and manipulate a matrix, you can perform many standard operations on it. For example, you can find the inverse of a matrix. You must be careful, however, since the operations are numerical manipulations done on digital computers. In the example, the matrix A is not a full matrix, but matlab's inverse routine will still return a matrix.
>> inv(A)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 4.565062e-18

ans =
1.0e+15 *
-2.7022 4.5036 -1.8014
5.4043 -9.0072 3.6029
-2.7022 4.5036 -1.8014

By the way, Matlab is case sensitive. This is another potential source of problems when you start building complicated algorithms.
>> inv(a)
??? Undefined function or variable a.

Other operations include finding an approximation to the eigen values of a matrix. There are two versions of this routine, one just finds the eigen values, the other finds both the eigen values and the eigen vectors. If you forget which one is which, you can get more information by typing help eig at the matlab prompt.

>> eig(A)
ans =
14.0664
-1.0664
0.0000
>> [v,e] = eig(A)

v =
-0.2656 0.7444 -0.4082
-0.4912 0.1907 0.8165
-0.8295 -0.6399 -0.4082
e =
14.0664 0 0
0 -1.0664 0
0 0 0.0000
>> diag(e)

ans =
14.0664
-1.0664
0.0000

No comments:

 
Top Blogs