Some hints on using MATLAB in high style - by Yi Jin Matlab was originally developed to perform numerical matrix computations, i.e., linear algebra. So it understands matrix, knows how to transpose a matrix, invert a matrix, multiply two matrices, factor a squre matrix into L*U, and of course, solve for Ax=b. Below is a short demo of linear algebra with matlab: >> A = [1 -1 -1 -1; 0 1 -1 -1; 0 0 1 -1; 0 0 0 1] A = 1 -1 -1 -1 0 1 -1 -1 0 0 1 -1 0 0 0 1 >> A' # Transpose A ans = 1 0 0 0 -1 1 0 0 -1 -1 1 0 -1 -1 -1 1 >> inv(A) #calculate A inverse ans = 1 1 2 4 0 1 1 2 0 0 1 1 0 0 0 1 >> A*inv(A) #matrix multiplication ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 >> b = [-2 -1 0 1]' #Define a row vector, then transpose it b = -2 -1 0 1 >> x = A\b # A\b means 'solve for Ax=b', it returns x x = 1 1 1 1 >> A*x # yes, A*x does equal to b ans = -2 -1 0 1 >> diag(b) # Generate a diagonal matrix with entries of b on its diagonal ans = -2 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 1 matlab encourages vectorized thinking to speed up the computation and simplify the program. A good matlab program is short,elegant yet powerful. For example, you can use ONLY 2 statements to generate the data set: x_k = (0.1)k, y_k = 1 + x_k - 2*x_k^2, k = 1,...,20 >> x = 0.1*[1:20]', y = ones(20,1) + x - 2*diag(x)*x ( >> is the matlab prompt, don't type it) (Try to find out why the above 2 statements generate the data set we want, isn't this beautiful?) Remember you need to launch matlab from the same directory where your 'xxx.m' files are located, otherwise matlab won't find these files. To launch matlab on paul, type: matlab -nojvm