2007年9月16日星期日

Stay Up Late for Serious Stuff

I've never gone to bed early since I came to Hong Kong, but this is the first time I do it for serious stuff, instead of entertaining myself.

Well, more seriously, for the damned involving assignment of PHYS382: Computational Physics

The algorithm is not difficult at all-- at least the core of them. Most of them are about interpolation and solving ODE, the methods for the latter are most straightforward-- the error is relatively great, of course! The greatest obstacle for me is the familiarity of the C language.

I began my life as a "coder" with Basic, and switched to Pascal at the age of 16 or so. I've only learned some Java before I came to university, which is the only thing I learned that at least has some resemblance with C. Of course I studied the idea of Object-Orientated with C++, but I never bother remembering the exact format of its code. I systematically learned some C language in a course one year ago, and got perfect mark in the final. That's all I had before I took the course.

The first obstacle is how to access the files on the hard disk. One of my classmates recommended a website with useful information about C++, but just wanna do it with a pure C style. Hence I searched the Web via Baidu until I found a page with the knowledge I needed.

Understanding how it works is way too far from actual coding, because so much practical problem should be considered. It is particularly hard for a theoretical physicist like me, who spend all day doing ideal experiments in the head. While dealing with the interpolation, I thought more point given would be more accurate, and used 500 points for calculation. Needless to say, it simply overflowed. The final result would not diverge, but during the calculation, huge numbers are to be dealt with. I realized it only after carefully analysis the algorithm, and reduced the number of points to 50, and it turned out to be just fine.

ODE solving is also far involving than I imagined, and some least expected errors are came across that made me call Baidu for help from time to time. One of these ridiculous things is: Before actually begin the calculation with floating number, one must do a meaningless calculation to make the Turbo compiler load a somewhat system to deal with floating number. This meaningless calculation will definitely go wrong, but the meaningful ones after that will go right. It is one of the flaws of Turbo compilers, and I only realized it by writing some tiny programs to test it.

Hence, I stayed up until almost 3, struggling with these codes, seemingly perfect but giving wrong result. I used all sort of debug methods I've ever learned. It is really agony to do such arduous, bad job. Finally, I got them all right.

However, during the process I've reviewed and learned many techniques I'll doubtlessly come across in other assignments. By that time, I think I can do them right far more quickly!

1 条评论:

匿名 说...

this website propecia cost nz - propecia side effects mental