mkdir using gcc

October 18, 2009 by sunhuan

#include<sys/stat.h>

mkdir(dirname, 0777);

The above implementation is platform-dependent and not in ANSI C standard. It only works under unix type machine.

Matlab, one pro and one con

October 4, 2009 by sunhuan

Matlab is great in the sense that it tremendously alleviates the pain of wrestling with data structure so that users can focus on the algorithmic part when playing with their academic or experimental toys. But this also contributes to the lack of awareness of the importance of data structure.

A video of my ubuntu desktop

October 4, 2009 by sunhuan

sin(x) = x + o(x), x<<1

September 20, 2009 by sunhuan

The title states a very simple approximation relation, which can be illustrated by the following plots:

error_sin_x

mesh

The first plot shows the error of an FEM solution for the Poisson equation

- u = sin(x)

with Dirichlet boundary condition

u = sin(x).

The 2nd plot shows the mesh.

The equation is solved with P1 elements. So at the left part when x is small, the FEM solution well approximates the true solution sin(x); while the error grows gradually bigger on the right part, as sin(x)  deviates from x to a greater extent.

All above = trivia + o(trivia)

The real purpose of this post is to show the lovely picture I got when doing some numerical tests.

The plot looks even prettier under a little finer mesh

error_sin_fine

dvi inverse search (back to Emacs) under Linux

September 3, 2009 by sunhuan

This tip is based on several on-line documents.

Add the following line to the file .emacs in your home directory:

(server-start)

Add the following line to .Xresources in your home directory (create the file if nonexistent)

xdvi.editor: emacsclient –no-wait +%l %f

Now run in the terminal:

xrdb .Xresources

Start the Emacs server

M-x server-start

Add the following package in the preamble of the latex file

\usepackage[active]{srcltx}

srcltx is not included in the basic latex package but is still available in the Ubuntu repository.

All set.

Compile the tex file, open the dvi by xdvi, and trace back by a Ctrl +left click.

The above can also be achieved with Kile + kdvi.

References:

1.  https://help.ubuntu.com/community/LaTeX

2. http://docs.kde.org/kde3/en/kdegraphics/kdvi/inverse-search-editor.html#editor-setup-emacs

LU decompostion in elementary linear algebra

August 17, 2009 by sunhuan

Prove the following

det ([A, B; C, D]) = det(A) * det(D – C A^{-1} B)

where A, B, C and D are sub-matrices.

This is a very common proof question related to determinant in a linear algebra course. But very few students will have learned LU decomposition by then. And it might be a good idea to rephrase this exercise question in the later numerics course.

A simple matlab question…

July 28, 2009 by sunhuan

Given a matrix A, say

A = rand(5);

together with two index arrays of the same length, e.g.

I = [1,2];

J = [3,4];

Q: How to shorten the following script into one line? i.e. how to vectorize the performance …

%start

vec =[];

for i=1:length(I)

vec = [vec, A(I(i),J(i))];

end

%end

Any suggestion is greatly appreciated!

test

July 28, 2009 by sunhuan

this is a blog entry from a simple blog software.

Hello world!

July 28, 2009 by sunhuan

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!