Matlab Matrix Operation - Malab Tutorials

Operation on Matrix in Matlab
There are also routines that let you find solutions to equations. For example, if Ax=b and you want to find x, a slow way to find x is to simply invert A and perform a left multiply on both sides (more on that later). It turns out that there are more efficient and more stable methods to do this (L/U decomposition with pivoting, for example). Matlab has special commands that will do this for you.

Before finding the approximations to linear systems, it is important to remember that if A and B are both matrices, then AB is not necessarily equal to BA. To distinguish the difference between solving systems that have a right or left multiply, Matlab uses two different operators, "/" and "\". Examples of their use are given below. It is left as an exercise for you to figure out which one is doing what.
>> v = [1 3 5]'
v =
1
3
5
>> x = A\v
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 4.565062e-18
x =
1.0e+15 *
1.8014
-3.6029
1.8014
>> x = B\v
x =
2
1
-1

>> B*x
ans =
1
3
5
>> x1 = v'/B

x1 =
4.0000 -3.0000 1.0000
>> x1*B

ans =
1.0000 3.0000 5.0000
Finally, sometimes you would like to clear all of your data and start over. You do this with the "clear" command. Be careful though, it does not ask you for a second opinion and its results are final.
>> clear
>> whos

No comments: