用 Maxima 进行符号计算

Maxima 是一个符号和数值计算系统, 它可以进行微分, 积分, 泰勒级数, 拉普拉斯变换, 常微分方程, 线性方程组, 多项式, 集合,列表, 向量, 矩阵, 张量的各种计算. Maxima 利用精确的分数, 任意精度的整数, 和可变长度的浮点数来产生高精度的数值结果.Maxima 可以对函数和数据进行二维和三维绘图.

$$\int \frac{dx}{x(1+2\sqrt{x}+\sqrt[3]{x})}$$

(%i4) integrate(1/(x*(1+2*sqrt(x)+x^(1/3))),x);


                                                     1/6
4 x    - 1
1/3    1/6        atan(----------)        1/6
log(x)   3 log(2 x    - x    + 1)         sqrt(7)      log(x    + 1)
(%o4) 6 (------ - ------------------------ - ---------------- - -------------)
6                 8                  4 sqrt(7)             4


Octave 解线性方程组

$Octave$ 解线性方程组的能力还没有 $matlab$ 强. 对于方程 $A\times X=B$, $Octave$ 要求 $A$ 是方阵, $B$ 是向量; 而 matlab 并没有这些要求, 假设 $A$ 是 $m\times n$, $B$ 是 $m\times k$, 则可以用 $matlab$ 算出 $X$, 它是 $n\times k$ 的.

$Octave$ 解方程组的式子为 $A\backslash B$. 下面提供两个例子

octave:1> #
octave:1> A=[0,2,0,1;2,2,3,2;4,-3,0,1.;6,1,-6,-5]

A =

0   2   0   1
2   2   3   2
4  -3   0   1
6   1  -6  -5

octave:2> B=[0;-2;-7;6]

B =

0
-2
-7
6

octave:3> A\B

ans =

-0.50000
1.00000
0.33333
-2.00000


octave:1> C=rand(5,5)
C =

0.847817   0.122730   0.298340   0.652850   0.985631
0.880412   0.618896   0.590534   0.485949   0.763285
0.358464   0.384306   0.469336   0.909417   0.554835
0.306760   0.672447   0.043989   0.371049   0.692044
0.314791   0.410965   0.487560   0.485444   0.892830

octave:2> D=rand(5,1)
D =

0.50708
0.99851
0.31515
0.70781
0.66774

octave:3> C\D
ans =

0.32657
0.77660
0.32264
-0.50477
0.37354


优秀 c 语言小实例 ---- qsort()

c 语言的标准库有一个函数实现了快速排序----qsort().

man 3 qsort

void qsort(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *));

base 指向要排序的数组. 长度为 nmemb, 每个元素的大小是 size. compar 是比较函数, 如果第一个参数"小于"("等于", "大于")第二个参数, 那么比较函数返回一个负整数(0, 正整数). 数组按升序排序, 改变"小于"的定义就可以按需要的顺序排序了. 下面是 man page 里的一个程序例子, 这个程序将它的参数进行排序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int
cmpstringp(const void *p1, const void *p2)
{
/* The actual arguments to this function are "pointers to
pointers to char", but strcmp(3) arguments are "pointers
to char", hence the following cast plus dereference */

return strcmp(* (char * const *) p1, * (char * const *) p2);
}

int
main(int argc, char *argv[])
{
int j;

if (argc < 2) {
fprintf(stderr, "Usage: %s <string>...\n", argv[0]);
exit(EXIT_FAILURE);
}

qsort(&argv[1], argc - 1, sizeof(argv[1]), cmpstringp);

for (j = 1; j < argc; j++)
puts(argv[j]);
exit(EXIT_SUCCESS);
}


  qsort(&argv[1], argc - 1, sizeof(argv[1]), cmpstringp);

int(*)(const void *, const void *)

&argv[1] 的类型为 char *, 作为实参传给 qsort 函数自动转变为 void * 型指针, 这样在 qsort 函数内部并不知道数组的类型(仅仅知道是void型数组), 因此需要一个参数 size 来标明数组元素的大小.

  return strcmp(* (char * const *) p1, * (char * const *) p2);

qsort 还能怎么用, 看看一个浮点数数组的排序该怎么写, 只需要改变比较函数就可以了

#define eps 0.000001
int numcmp(const void *x,const void *y){  // 排序比较函数
float z=*((double*)x)-*((double*)y);
if(z>eps) return 1;
if(z<-eps)	return -1;
return 0;
}

float price[10] = {32.0, 12, 8, 45.1,
13, 30, 53.2, 34.1, 80, 22}
qsort(price, 10, sizeof(float), numcmp);


换成了 ubuntu 11.10

• /boot   /dev/sda1    ---100M
• /home  /dev/sda2   ---120G
• LFS       /dev/sda3   ---10G
• /             /dev/sda5 ---40G
• swap                       ---2.5G

MIT教授对作业、学习小组及考试的看法

---------------------------
Collaboration policy.This is extremely important so everybody pay attention. If you are asleep now wake up. Like that's going to wake anybody up, right?
The goal of homework, Professor Demaine and my philosophy is that the goal of hemework is to help you learn the material. And one way of helping to learn is not to just be stuck and unable to solve something, because then you're in no better shape when the exam roles around, which is where we're actually evaluating you. So, you're encouraged to collaborate.

But there are some commonsense things about collaboration. If you go and you collaborate to the extent that all you're doing is getting the information from somebody else, you're not learning the material and you're not going to do well on the exams. In our experience, students who collaborate generally do better than students who works alone. But you owe it to yourself, if you're going to work in a study group, to be prepared for your study group meeting. And specifically you should spend a half an hour to 45 minutes on each problem before you go to group so you're up to speed and you've tried out your ideas. And you may have solutions to some, you may be stuck on some other ones, but at least you applied yourself to it. After 30 to 45 minutes, if you cannot get the problem, just sitting there and banging your head against it makes no sense. It's not a productive use of your time. And I know most fo you have issues with having time on your hands, right? So, don;t go banging your head against problems that are too hard or  where you don't understand what's going on or whatever. That's when the study group can help out. And, as I mentioned, we'll have homework labs which will give you an opportunity to go and do that and coordinate with other students rather than necessarily having to form your own group. And the TAs will be there. If your group is unable to solve the problem, then talk to other groups or ask your recitation instructor. And, that's how you go about solving them.
Writing up the problem sets, however, is your individual responsibility and should be done alone. You don't write up your problem solutions with other students, you write up on your own. And you should on your problem sets, because this is an academic place, we understand that the source of academic information is very important, if you collaborated on solutions you should write a list of the collaborators. Say I worked with so an so on this solution. It does not afect your grade. It's just a question of being scholarly. it is a violation of this policy to submit a problem solution that you cannot orally explain to a member of the course staff. You say oh, well, my wrte-up is similar to that other person's, I didn't copy them. We may ask you to orally explain your solution. If you are unable, according to this policy, the presumptions is that you cheated. So do not write up stuff that you don't understand. You should be able to write up the stuff that you understand. Understand why you're putting down what you're putting down. If it's not obvious, no collaboration whatsoever is permitted in exams...

流密码及RC4算法

ps: 学过c语言的童鞋看这篇文章没难度

RC4用两步来生成密码流

for i from 0 to 255
S[i] := i
endfor
j := 0
for i from 0 to 255
j := (j + S[i] + key[i mod keylength]) mod 256
swap values of S[i] and S[j]
endfor

i := 0
j := 0
while GeneratingOutput:
i := (i + 1) mod 256
j := (j + S[i]) mod 256
swap values of S[i] and S[j]
K := S[(S[i] + S[j]) mod 256]
output K
endwhile
output K 一次产生一字符长度（8bit）的密钥流数据，一直循环直到密码流和明文长度一样为止。

http://en.wikipedia.org/wiki/RC4
MJB Robshaw - 1995  Stream Ciphers

hello, world

Hi，我是一名本科大三学生（2011），就读于中山大学数学与应用数学专业，大学前基本上没碰过电脑，大一时学了c和c++，仍然对电脑有陌生和恐惧感，当我大二时装上了ubuntu linux之后，慢慢对电脑感兴趣了，而后花很多时间在互联网上，觉得互联网真是太伟大了，由衷的钦佩和感激为丰富互联网内容保持互联网运作而默默贡献的程序员们。分享的理念深入了我的内心，希望自己能做一些有意义的事情，就想建个博客。