Home My Accounts | Newsletter | News Flash | Contact Us | Search

 

Issues/Circulation
Current Issue: December 2004
Other Issues
Applications
Matlab Release 14 on Willow
Setting up the MATLAB Environment
Using MATLAB at MCSR, Part II
Dplace Utility
Running CPMD on Sweetgum
Amber 7 on Redwood
Removing ^M From Files
Systems
Redwood Quotas and /ptmp Space
The MCSR Parallel-O-Gram
Getting Started with MATLAB at MCSR, Part II

A short article on Matlab V

See also Getting Started with MATLAB at MCSR, Part I and Setting Up the MATLAB Environment at MCSR

This is a short article showing users how to solve a 3 by 3 linear equation and how to obtain the inverse of a non-singular matrix using version 7.0 release 14 of Matlab on willow. These examples should also work using the Matlab 13 installation on sweetgum.  Also discussed here are an example of how to obtain the covariance for a matrix and a small example of an eigenvalues problem. The five examples mentioned here are simple and elementary; later articles will expand this effort to include more advanced topics.

 

Once you have set up your willow or sweetgum account, according to the above instructions in  Setting Up the MATLAB Environment at MCSR to run matlab via command-line on sweetgum or willow, you can activate Matlab on willow or sweetgum, and run the following examples.

 

matlab

 

The above command activates Matlab and the double prompt “>>” below indicates that Matlab is at your service. You can continue 

 

>> 

 

You can then enter a 3 by 3 non-singular matrix as follows:

 

>> a=[1 1 1

1 -1 1

1 1 -1 ]

 

Matlab will respond by printing your input matrix like this:

 

a =

 

     1     1     1

     1    -1     1

     1     1    -1

 

Next, you can enter an input vector, like this:

 

>> b=[6

2

0 ]

 

Matlab should respond like this:

 

b =

 

     6

     2

     0

 

Continue as follows:

 

>> x=a\b          ; user enters “x=a\b” to tell Matlab to divide matrix “a”

                          ; by vector “b” and put the results into vector x:

 

Matlab should respond by printing the one by three vector “x” which is the solution.

 

x =

 

     1

     2

     3

 

>> 

 

For a complete discussion on solving a set of linear equations, users may look under:

http://www.mcsr.olemiss.edu/appssubpage.php?pagename=imsl.inc

 

Below is the second example of solving linear equations. This set of equations is the same as those solved using IMSL, as reported in the above website.

 

>> a=[33. 16. 72.

-24. -10. -57.

18. -11. 7. ]

 

Above is the 3 by 3 non-singular matrix entered by the user.

 

a =

 

    33    16    72

   -24   -10   -57

    18   -11     7

 

Matlab responds as shown above by printing the user’s input matrix.

 

>> c=[129.

-96.

8.5 ]

 

Above is the user’s input vector.

 

c =

 

  129.0000

  -96.0000

    8.5000

 

Again, Matlab prints the vector “c” entered by the user.

 

>> x=a\c                ; user enters “x=a\c” to tell Matlab to divide matrix “a” by the vector 

                                ; “b” and put the result (answer) into vector x:

 

x =

 

    1.0000

    1.5000

    1.0000

 

And the above one by three vector “x” is the solution to the original three by three matrix “a” and the vector “c”.

 

The above three by three set of equations are solved using both IMSL and Matlab. Users may compare the two packages (IMSL and Matlab) and decide which package better fits their needs, since IMSL requires a lot of Fortran programming and Matlab does not.

 

>> a=[1 1 1

1 -1 1

1 1 -1 ]

 

Above is the 3 by 3 non-singular matrix entered by the user. To obtain the inverse of a non-singular matrix “a” above, user enters at the Matlab prompt:

 

>> inv(a)

 

ans =

 

         0    0.5000    0.5000

    0.5000   -0.5000         0

    0.5000         0   -0.5000

 

>> 

 

To obtain the covariance of a matrix, user enters at the Matlab prompt:

 

>> cov(a)

 

ans =

 

         0         0         0

         0    1.3333   -0.6667

         0   -0.6667    1.3333

 

>> 

 

To obtain an eigenvalues of a matrix that is called s1, user enters:

 

>> z1=[1 2

2 1]

 

Matlab responds by printing the user’s input matrix.

 

z1 =

 

     1     2

     2     1

 

To obtain the actual eigenvalues, the user enters:

 

>> s1=eig(z1)

 

; And the answer is:

 

s1 =

 

    -1

     3

 

>> 

 

From the study of eigenvalues we know that the eigenvaules are the solution to the following quadratic equation:

 

X**2 -2X -3=0.

 

By inspection we see that -1 and 3 are the solution.

 

“;” Indicates comments entered by the author and is not a part of Matlab programming.

 

Comments: In our next article we will explain the role of eigenvalues and eigenfunctions in math, physics and engineering and will obtain eigenfunctions using both IMSL and Matlab. From the study of Matrix Algebra we know that the inverse of an inverse is the original matrix, it is left to the users to check this out. A graduate course in matrix algebra and another one in mathematical statistics will help users follow this short article and some of the other Matlab’s contents.

The website for our article on solving linear equations using IMSL is:

 

http://www.mcsr.olemiss.edu/computing/imsl.html

--------------------------------
Last Modified: Wednesday, 22-Sep-2004 10:29:30 CDT
Copyright © 1997-2005 The Mississippi Center for Supercomputing Research. All Rights Reserved.
[an error occurred while processing this directive]