Wednesday, November 19, 2008

MATLAB: Don't ', transpose(it)

Doing a little homework for ME 7040, I discovered that there is more to transposing a matrix than just rows becoming columns and vice versa. I was doing a simple stress, strain, displacement analysis of a beam under static load. The code snippet in question is when the elemental stiffness matrix needed to be calculated by:
k = int(int(B'*D*B,r,-0.5,0.5),s,-0.5,0.5)
B is a 3xn matrix of shape functions and D a 3x3 relationship of Modulus of Elasticity and Poisson's ratio. There is obviously more to this code, including the calculations of stress and strain and the writing of an output file.

Running the code using the prime ('), the code took 143.106 seconds to run. I was initally confused by how long it took because the matrices were not that large. I then heard about the function transpose() and decided to use that. In code form:
k = int(int(transpose(B)*D*B,r,-0.5,0.5),s,-0.5,0.5)
This took only 19.735 seconds to run. So digging a little further, the operator ', also checks for complex conjugates of the matrix as well.

In conclusion, if you know that you are not dealing with complex numbers, you may want to use the transpose function and not its operator.

Tip: To time the running time of your code, put tic on the top line and toc on the last line.

Tuesday, November 18, 2008

SCP + SSH: Copying files from Windows to Linux

At the university I attend, it is mostly all about Windows and there is no support for linux so many things have to be done by the user to get anything done. However, most linux users are used to trying this on your own. Here I will show you how to successfully transfer files from your linux box at home to a windows computer at work/school. Linux commands refer to Ubuntu. Please see your distro's guide on installing packages.

Software Required:
Windows: Cygwin
Linux: openssh

Configuring linux box:
To install openssh, in terminal type
sudo apt-get install openssh-server
If the linux box is behind a router, please open the port corresponding to ssh. Default is 22. For more information please visit portforward.com.

To test the installation of ssh type:
ssh localhost
If everything works, then that should be up for setting up the linux box.

Configuring Windows:
After downloading setup.exe from the link above, double click to run. The important part of the installation is "Selecting Packages" diaglog box.
Expand the Net tree by pressing the +. Scroll down and look for openssh and click on "Skip" to change it to "Install". You will notice a check box under column B. Click Next when finished and complete the installation.

Operating the Windows Box:
After installation, open cygwin and a terminal will appear. The syntax for scp is:
scp [options] [[user@]host1:]filename1 ... [[user@]host2:]filename2

To copy 'report.pdf' from your Fall 2008 folder on your home directory, you would type:
scp report.pdf user@serverip:"/home/user/Fall 2008/" .
This will save report.pfg into your home directory. Notice the "."

More Information:

Good Luck.