Sunday, December 23, 2012

Java

final  keywords is the same as const in C/C++. A method can be declared as final, which means it cannot be overridden in any classes that extend the one it is in. A final method is often used to insist that particular functionality be used in all child classes. The final modifier can also be applied to an entire class. A final method class cannot be extended at all. Using the final modifier to restrict inheritance abilities is a key design decision. It should be done in situations in which a child class could possibly be used to change functionality that you, as a designer, specifically want to be handled a certain way.

Create a Scanner object object in order to invoke its methods. Object in java are created using the new operator.
Scanner scan = new Scanner(System.in); 
scan.next*             

enum should be define in a class and before the main() function

The compiler will issue an error if a static method attempts to use a non-static variable. A static method can reference static variables because static variables exist independent of specific objects. Therefor, all static methods, including the main method can access only static or local variables.

The this reference can be used to refer to the currently executing object.


System.out.println(Runtime.getRuntime().maxMemory());
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());


Declaring an array:   int [] height = new int[10];
The index operator performs automatic bounds checking, which ensures that the index is in range for the array being referenced.

Java accepts variable-length parameters lists. By using some special syntax in the formal parameter list of the method, we can define the method to accept any number of parameters. The parameters are automatically put into an array for easy processing in the method. For example
public void printGrades (Grade ... grades)
{
        for (Grade letterGrade : grades)
                System.out.println(letterGrade);
}
The varying parameters much come last in the formal arguments. A single method cannot accept two sets of varying parameters.

Two dimensional array
int [][] table = new int[5][10];
for (int row = 0; row < table.length; row++)
        for (int col = 0; col < table[row].length; col++)

The super reference: super can be used in a class to refer to its parent class. Using the super reference, we can access a parent's members. Like the this reference, what the word super refers to depends on the class in which it is used.
A common use of the super reference is to invoke a parent's constructor. A child's constructor is responsible for calling its parent's constructor. Generally, the first line of a constructor should use the super reference call to a constructor of the parent class. If no such call exists, java will automatically make a call to super with no parameter ar the beginning of the constructor.

An abstract class canot be instantiated an usually contains one more abstract methods, which have no definition. A class is declared as abstract by including the abstract modifier in the class header. Any class that contains one or more abstract methods must be declared as abstract. In abstract classes, the abstract modifier must be applied to each abstract method.

We can create a polymorphic reference in Java in two ways: using inheritance and using interfaces.

A java Interface is a collection of constants and abstract methods. A class that implements an interface use the reserved word implements followed by the interface name in the class header. Multiple classes can implement the same interface, providing their own definitions for the methods.
public interface Encryptable
{
        public void encrypt();
        public String decrypt();
}
public class Secret implements Encryptable
{
        public void encrypt() {}
}

class ManyThings implements Interface1, Interface2, Interface3
{
        // Implements all methods of all interfaces
}

Sunday, December 2, 2012

Customize Xterm, the original and best terminal…

Note: Translated from this original link:

1. root@debian:~# vim /root/.Xresources
2. content of the file

! Use a nice truetype font and size by default... 
xterm*faceName: DejaVu Sans Mono Book 
xterm*faceSize: 12 

! Every shell is a login shell by default (for inclusion of all necessary environment variables) 
xterm*loginshell: true 

! I like a LOT of scrollback... 
xterm*savelines: 16384 

! double-click to select whole URLs :D 
xterm*charClass: 33:48,36-47:48,58-59:48,61:48,63-64:48,95:48,126:48 

! DOS-box colours... 
xterm*foreground: white 
xterm*background: balck
xterm*cursorColor: green
xterm*color0: rgb:00/00/00 
xterm*color1: rgb:a8/00/00 
xterm*color2: rgb:00/a8/00 
xterm*color3: rgb:a8/54/00 
xterm*color4: rgb:00/00/a8 
xterm*color5: rgb:a8/00/a8 
xterm*color6: rgb:00/a8/a8 
xterm*color7: rgb:a8/a8/a8 
xterm*color8: rgb:54/54/54 
xterm*color9: rgb:fc/54/54 
xterm*color10: rgb:54/fc/54 
xterm*color11: rgb:fc/fc/54 
xterm*color12: rgb:54/54/fc 
xterm*color13: rgb:fc/54/fc 
xterm*color14: rgb:54/fc/fc 
xterm*color15: rgb:fc/fc/fc 

! right hand side scrollbar... 
xterm*rightScrollBar: true 
xterm*ScrollBar: true 

! stop output to terminal from jumping down to bottom of scroll again 
xterm*scrollTtyOutput: false

3. xrdb -merge ~/.Xresources

4. default configuration
/etc/X11/app-defaults/XTerm

5. xrdb -load /etc/X11/app-defaults/XTerm


Sunday, November 18, 2012

Problem Sets


1. Collatz Conjecture

void collatz(unsigned int n){         while (n > 1)         {                  printf("%u -> ", n);                  if (n % 2)                          n = 3*n + 1;                  else n /= 2;
  }         printf("%d", n);}


2. Binomial theorem

(a+b)^n = ∑(n,k)a^k b^(n-k)

A function that is easy to compute but hard to invert is often called a one-way function. In the context of encryption, we desire that ek be an injective and one-way function so that decryption can be performed. Unfortunately, although there are many injective functions that are believed to be one-way, there currently do not exist such functions that can be proved to be one-way.
For a public-key crypto-system, it is not sufficient to fine an injective one-way function. We do not want ek to be one-way from Bob's point of view, because he needs to be able to decrypt messages that he receives in an efficient way. Thus it is necessary that Bob possesses a trapdoor, which consists of secret information that permits easy inversion of ek. So, we say that a function is a trapdoor one-way function if it is a one-way function, but it becomes easy to invert with the knowledge of a certain trapdoor.

Cyclic Groups and Subgroups


Repost from this link http://dogschool.tripod.com/cyclic.html
9. Cyclic Groups and Subgroups

Let's start with the number 1. We'll allow ourselves to add or subtract the number 1 to get to new numbers.
Question: what integers will we be able to reach by this process?
Answer: all of them.
To get to 17 simply add 1 16 times. To get to -42 simply subtract 1 43 times. The fact that the integers can be "built" by adding and subtracting 1 means that the additive group of integers is a cyclic group.
Now let's look at the Attayun-HOOT! group. The entire Attayun-HOOT! group can be "built" from repeated applications of R:
  • R = (R1) = R
  • R • R = (R2) = B
  • R • R • R = (R3) = L
  • R • R • R • R = (R4) = A
Groups that can be generated in their entirety from one member are called cyclic groups. For infinite groups we have to clarify what we mean by "generated from." For example in the additive group of Integers starting with 1 and adding it over and over to itself will never get a negative number nor the identity zero. Thus for a cyclic group we have the definition that all the elements may be generated from a single element together with its inverse. For finite cyclic groups the addition of "together with its inverse" is not needed. That statement probably should be stated as a theorem.Theorem: If a finite group G can be generated from one of its elements, a together with its inverse a-1 then it can be generated from a alone.
Proof:
The strategy of the proof is to show that we can generate a-1 from repeated applications of a.
If G is finite then the various powers of a cannot all be distinct [note that this would not necessarily follow if G is infinite]. Therefore for some two different positive integers, j and k

a • a • a • . . . • a • a(j times) = a • a • a • . . . • a • a(k times)
Assume without loss of generality that j is greater than k (Why can we do this?). Now if we multiply both sides of the equation by a-1 • a-1 • a-1 • . . . • a-1 • a-1(k times) then we end up with

a • a • . . . • a(j-k times) = e
That means that a-1 = a • a • . . . • a(j-k-1 times).
Let's get away from all the " . . . " and "(j-k times)" by using exponential notation. Just as we do for multiplication of regular old numbers we can express repeated application of the group operation by a given element with exponential notation. So we'll agree that for an element a of a group G with operation •
  • an means a • a • a • . . . • a (n times)
  • a-n means a-1 • a-1 • a-1 • . . . • a-1 (n times)
  • a0 means the identityb element e
We find that with this notation the basic law of exponents all work as in regular arithmetic namely
  • a• aam+n
  • The inverse of ais a-n
  • (a)amn
With this notation we mean that a power of a is an where n is any integer: positive, negative or zero.
Cyclic Subgroups
If we pick some element a from a group G then we can consider the subset of all elements of G that are powers of a. This subset forms a subgroup of Gand is called the cyclic subgroup generated by a. If forms a subgroup since it is
  • Closed. If you multiply powers of a you end up with powers of a
  • Has the identitya • a-1 a0 = e
  • Has inverses. The inverse of any product of a's is a similar product of a-1 's.
But this is the long way of proving subgrouphood. Let's use our theorem that says if x and y are in the subset implies that x • y-1 is in the subset then the subset is a group. This is simple here. If y is a power of a then so is y-1 and so, therefore, is x • y-1 .
A few facts about cyclic groups and cyclic subgroups:
  1. Cyclic groups are Abelian.
  2. All groups of prime order are cyclic.
  3. The subgroup of a group G generated by a is the intersection of all subgroups of G containing a
  4. All infinite cyclic groups look like the additive group of integers.
[Exercise: prove the first fact.]The second fact is a result of Lagrange's theorem. If G is a group of prime order p then take any non-identity element a and look at the subgroup generated by it. The order of the subgroup must be a divisor of the order of G (Lagrange's Theorem) but since G is of prime p order the only divisors ofp are 1 and p itself. Since a isn't the identity the subgroup it generates must have more than one element. Therefore its order must be pand it must be Gitself -- G is cyclic. Furthermore since the choice of a was only limited by its not being the identity it follows that G can be generated by any of its elements other than e.
The third fact is rather simple. Any subgroup containing a contains a-1 and therefore contains any products of a's and a-1 . Thus any subgroup containing acontains the cyclic subgroup generated by a. Since the cyclic subgroup generated by a is a subroup the fact follows.
The fourth fact is poorly stated. "looks like" is not a well understood piece of mathematical terminology. We'll tighten things up as we go along.
Suppose I is an infinite cyclic group generated by the element a. Then any element of the group is of the form awhere n is an integer. Then the multiplication rule for this group ends up being

[a] • [a] = am + n
We can tighten up the notation of this group by letting the integer n stand for the element a. Then the "multiplication" rule for the group becomes

m • n = (m+n)
But this is just the behavior of the additive group of integers.
We have a one to one correspondence [acorresponds to n] which is preserved by the group operation [You can either perform the operation in one group and then find the corresponding element in the other or you can first find the corresponding elements in the other group and then perform the operation on them. The result is the same. And it works both ways. This is a group isomorphism, a concept we have looked at but haven't rigorously defined yet.
Definition: Two groups G and H are isomorphic if there exists a one-to-one relation G –> H between them such that for any x and y in Gf(x) • f(y) = f(x * y). The one-to-one relation f is called an isomorphism. Thus two groups are said to be isomorphic if an isomorphism exists between them.
[Note on my notation I've used two different symbols for the group operations in that last passage. • represents the group operation in H and * represents the group operation in G This was to emphasize that we are dealing with two different groups each with its own group operation.]
[Exercise: show that the inverse relation works too. That is, show that if g : H –> G is the inverse of f then for any u and v in H it is true that g(u) * g(v) = g(u • v).]
One of the most common examples of a group isomorphism is found in the theory of logarithms. Let : G –>H be the logarithm function and let G be the group of positive real numbers under multiplication and let H be the real numbers under addition. It turns out that

Log(x) + Log(y) = Log(xy)
This together with the fact that Log is a one-to-one function (it has an inverse -- the exponential or "antilog" function) makes this a group isomorphism. This used to have great practical importance back in the days before pocket calculators. Long numerical calculations involving multiplication (and taking of roots and powers) could be simplified by doing addition of the Logs of the numbers. In those days no scientist or engineer was far from his table of Logarithms.
The following are basic facts about group isomorphism:
If fG –> H is a group isomorphism then:
  • If e is the identity in G then f(e) is the identity in H>.
  • The inverse of f(a) in H is F(a-1).
Now we can restate our poorly stated fourth fact:4. All infinite cyclic groups are isomorphic to the additive group of integers.
The isomorphism is simply an –> n as we have already seen.
The main point about cyclic groups and isomorphism is that all finite cyclic groups of the same order are isomorphic. Thus there is only one cyclic group (up to isomorphism) of order, say, 6. If we let a be a generator then the elements of the cyclic group of order 6 are aa2a3a4a5, and a6 = e.
The canonical example of a cyclic group of order n is the additive group of integers mod nZ/nZ. The cayley table for Z/6Z is
+012345
0012345
1123450
2234501
3345012
4450123
5501234

Note how each row (or column) is simply the previous row (or column) cycled forward one space.
The set of integers mod n is not a group under multiplication because 0 has no inverse – there is nothing that multiplies 0 to give 1, the identity element for multiplication. If n is a prime number and we throw out zero the remaining elements of Z/nZ does form a group – a cyclic group. Here's the Cayley table for the non-zero elements of Z (mod 7)
×123456
1123456
2246135
3362514
4415263
5531642
6654321

The cyclic nature of the group isn't apparent from a glance at the table. However if we consider the powers of 5 then we find that 5 generates the entire group. Similarly 3 also generates the group. By rearranging the elements of the Cayley table the cyclic nature is readily seen.
×154623
1154623
5546231
4462315
6623154
2231546
3315462

[Exercise: The above table was rearranged by listing the 0th power of 5 first, then the first power of 5 then the 2nd power of 5 etc. Rearrange the table in order of powers of 3 such that its cyclic structure is evident.]
We can form a cyclic subgroup of any group by grabbing an element a of the group an looking at the set of all its powers. This gives the subgroup generated by a notated as < a >. Now by Lagrange's theorem the number of elements in < a > (the order of the subgroup) must be a divisor of the order of the group. Also if k is the order of < a > then k is the least positive integer with ak = e. For any element of a group the least positive integer that gives the identity when the element is raised to that power is called the order of the element. Thus the order of a cyclic subgroup and the order of its generator are the same number.
We might remark at this point that any subgroup of a cyclic group must itself be cyclic. If G is generated by a and S is a subgroup of G Then S must be cyclic. To see this consider all the elements of S. They can all be expressed as powers of a. Let k be the least positive power of a that is in S. If every element is not a power of ak then there is some element am where m is positive and not a mulitple of k. Let p be the greatest multiple of k that is less than m. Then m - p is less than k. But this means that am • a-p = am-p is in S. This contradicts the choice of k as the smallest positive power of a in the subgroup. Thus all elements of S are generated by ak and S is cyclic.
Now if for any element its order divides the order of the group then it follows that if n is the order of the group then an = e for any element a of any finite group. [Why must this be so?]
Now we have a constrained converse of Lagrange's theorem. It is true that for cyclic groups if n is a divisor of the order of the group then the group has a subgroup of order n. To see why this must be so recall that a cyclic group is generated by the powers of one of its elements. Let's see why this must be forthe cyclic group of order 12.

C12 = { e, a, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11}
Since 3 divides 12 (i.e. 3 × 4 = 12) then (a3)4 = a12 = e. Thus a3 is an element with order 4. (If it were less then a power of a less than 12 would equal e). Thus a3 generates a subgroup of order 4. Similarly a4 generates a subgroup of order 3 and a2 generates a subgroup of order 6 while a6 generates a subgroup of order 2. There are always the trivial subgroups of orders 1 and 12 (The subgroup containing only the identity and the whole group considered as a subgroup of itself).
There is nothing special about the number 12. Let a cyclic group have order n. If r is a divisor of n then there is some number s such that rs = n. Let a be an element of the group with order n. (it must have one if it is cyclic) Then ar is of order s and therefore generates a cyclic subgroup of order s while asgenerates a subgroup of order r.
We can go a bit further in looking at subgroups of cyclic groups. Not only does a cyclic group have a subgroup of order r for every r that divides the order of the group but it has exactly one subgroup for each distinct divisor of n. To see this suppose that S is a subgroup of a cyclic group of order n and a is a generator. Suppose S has order r where rs = n. Then S is generated by one of its elements, ak for some k. This means that ak has order r which in turn means that k times r equals some multiple of n. Now since rs = n, s must divide k. Therefore ak is in the group generated by as which is of order r. However ak generates a group of order r. Thus r elements of the subgroup generated by ak are in the subgroup generated by as which has only r elements. The subgroups must be identical.
Finally let's use group theory to deduce a famous result of number theory. Consider the non-zero members of integers mod p where p is prime. If we let our binary operation be multiplication mod p then we get a group with p-1 elements (we've thrown out zero). [Is it really a group?
  • It's closed. Since p is prime any two non-zero elements (means not divisible by p) multiply to give a non-zero element.
  • It's associative. Multiplication is associative in regular integers and therefore in integers mod p.
  • 1 is the identity
  • Since p is prime the cancellation law holds. [If ax = ay then ax - ay = a(x-y) is divisible by p. Since a is not divisible by p (or else it would be 0 mod p and that's been thrown out) x - y must be a multiple of p. This means that x = y mod p.] So the same element cannot appear twice in any row or column of the Cayley table of this system which means that every element appears once. More specifically 1 appears exactly once in every row and in every column and thus every element has an inverse.]]
If a is in this group then ap-1 = 1. [Why?] That means that if n is an integer that is not divisible by the prime p then
np-1 = 1 mod p
This result is known as Fermat's Little Theorem.

Extended Euclidean Algorithm
每组数字都拆分成 rem = fst*1 - snd*quo 的形式,然后将后续的rem用前面的右面的式子替换掉,最终就能得到结果了。

Chinese Remainder Theorem
假如所求数字为x,余数分别为(a1,a2,..,ar),模数分别为(m1,m2,...,mr)
首先求出M=m1*m2*...*mr
然后Mi = M/mi
令yi = Mi' mod mi
x则等于∑ai*Mi*yi

An element a having order p-1 mod p is called a primitive element modulo p. Observe that a is a primitive element modulo p if and only if
{a^i | 0≤i≤p-2}∈Zp*
so any elements b∈Zp* can be written as a^i where 0≤i≤p-2 in a unique way, which means gcd(i, p-1) = 1. For example, P=13, then p-1=12, if we choose a=2, then the primitive element should be 2^1 = 2; 2^5 mod 13=7, 2^7 mod 13 = 11; 2^11 mod 13 = 7.

In 2002, it was proven by Agrawal, Kayal and Saxena that there is a polynomial-time deterministic algorithm for primality testing. However, in practice, primality testing is till done mainly by using a randomized polynomial-time Monte Carlo algorithm such as the SOLOVAY-STRASSEN ALGORITHM or the MILLER-RABIN ALGORITHM.

A Las Vegas algorithm may not give an answer

Euler's generalization of fermat.
φ(N) = |(Zn)*|, for all x∈Zn*, x^φ(N) = 1 in Zn
for example, N=12, then  φ(12) = {1,5,7,11}=4, 5^12=1 in Z12

Tips

Crack Slickedit 2012 

17.0.2 (Win7 x64)
1. Open the vs.exe with UEStudio
2. Search this hex string "40 0F B6 C7 48 8B 5C 24"
3. Replace the first 4 bytes "40 0F B6 C7" with "B0 01 90 90"
4. Save it and reopen, done.

17.0.3 (MAC 10.8.2)
1. Open the vs with UltraEdit
2. Find the offset 146DDD5h
3. Replace "89 D8" with "B0 01"
4. Save it and reopen, done.


__text:0000000100017DB7 loc_100017DB7:                          ; CODE XREF: __ZL15checkoutLicenseb+144 j
__text:0000000100017DB7                 movsxd  rcx, edx
__text:0000000100017DBA                 mov     rax, [r9+rcx*8]
__text:0000000100017DBE                 movzx   eax, byte ptr [rax+r8]
__text:0000000100017DC3                 cmp     edx, esi
__text:0000000100017DC5                 jnz     short loc_100017DA6
__text:0000000100017DC7                 cmp     al, 2Dh
__text:0000000100017DC9                 jnz     short loc_100017DAD
__text:0000000100017DCB
__text:0000000100017DCB loc_100017DCB:                          ; CODE XREF: __ZL15checkoutLicenseb+D5 j
__text:0000000100017DCB                                         ; __ZL15checkoutLicenseb+139 j ...
__text:0000000100017DCB                 xor     ebx, ebx
__text:0000000100017DCD
__text:0000000100017DCD loc_100017DCD:                          ; CODE XREF: __ZL15checkoutLicenseb+1A6 j
__text:0000000100017DCD                                         ; __ZL15checkoutLicenseb+1BB j
__text:0000000100017DCD                 mov     rdi, r15
__text:0000000100017DD0                 call    __ZN9slickedit8SEStringD1Ev ; slickedit::SEString::~SEString()
__text:0000000100017DD5
__text:0000000100017DD5 loc_100017DD5:                          ; CODE XREF: __ZL15checkoutLicenseb+1BF j
__text:0000000100017DD5                 mov     al, 1  ; original is 84 C0
__text:0000000100017DD7                 add     rsp, 28h
__text:0000000100017DDB                 pop     rbx
__text:0000000100017DDC                 pop     r12
__text:0000000100017DDE                 pop     r13
__text:0000000100017DE0                 pop     r14
__text:0000000100017DE2                 pop     r15
__text:0000000100017DE4                 leave
__text:0000000100017DE5                 retn




Wednesday, November 7, 2012

Randomized Algorithm

全概率公式
设试验E的样本空间为S,A为E的事件,B1, B2,......,Bn为S的一个划分,且P(Bi)>0,则有
P(A) = P(A|B1)P(B1) + P(A|B2)P(B2) +......+P(A|Bn)P(Bn)

乘法定理
P(ABC) = P(C|AB)P(B|A)P(A)

P(A) = P(A|B)P(B) + P(A|B补)P(B补)
P(B|A) = P(AB)/P(A) = P(A|B)P(B) / (P(A|B)P(B) + P(A|B补)P(B补))

CRYPTOGRAPHY PART

A field with order m only exists if m is a prime power, i.e. m = p^n, for some positive integer n and prime integer p. p is called the characteristic of the finite field. (proof?)

GF(2) modulo addition is equivalent to XOR; GF(2) multiplication is equivalent to AND.

GF(2^m) is called extension fields.Extension fields can be represented as polynomials and the computation in the extension field is achieved by performing a certain type of polynomial arithmetic.

Every field GF(2^m) requires and irreducible polynomial P(x) of degree m with coefficient from GF(2). Not all polynomials are irreducible. For example the polynomial 4 3 1 0 is reducible since (2 1 0)(2 0) and hence cannot be used to construct the extension field GF(2^4). If the polynomial can be divided to more than two single expressions, then it is reducible. The irreducible polynomial for AES is 8 4 3 1 0, which is part of the AES specification.

AES Algorithm
1. AddRoundKey Layer. XOR the matrix and key matrix. This will execute one time at the beginning of AES.
2. SubByte Layer. Look up S-BOX and replace each item in matrix
3. ShiftRow Layer. The i-th row (1≤i≤4) shifts i-1 position to the left.
4. MixColumn Layer. Each column multiply with an constant matrix.

Key Schedule
1. Chose the i+3 column and shift one position to DOWN.
2. SubByte operation to this new column.
3. XOR with the i-th column and the round number. This will be the i+4 column.
4. Round the above operations.

Extended Euclidean Algorithm
void eea (int a, int b, int& gcd, int& x, int& y)
{
    x=0, y=1;
    int u=1, v=0, m, n, q, r;
    gcd = b;
    while (a!=0)
{
        q=gcd/a; r=gcd%a;
        m=x-u*q; n=y-v*q;
        gcd=a; a=r; x=u; y=v; u=m; v=n;
    }
}

Fermat's Little Theorem
a^{p-1} \equiv 1 \pmod p.
Proof:
1. 1 2 3...p-1 is a ring mod p
2. Multiply a with 1 2 3...p-1 and then mod p, this is still a ring on 12 3...p-1
3. then we know a \times 2a \times 3a \times \cdots \times (p-1)a \equiv 1 \times 2 \times 3 \times \cdots \times (p-1) \pmod p.
4. a^{p-1} (p-1)! \equiv (p-1)! \pmod p.
5. a^{p-1} \equiv 1 \pmod p.\,\!

Privately Outsourcing Computation


Thursday, October 25, 2012

Pearls of Latex and Matlab

1.1 Insert a graph
\usepackage{graphicx}

\begin{figure}[tbp]
\centering
\includegraphics{psu.jpg}
\caption{Including an external graphics file with...}
\end{figure}

1.2 List
\begin{itemize}
\item First Item
\item Second Item.
\item Third item.
\end{itemize}

\begin{enumerate}
\item First Item
\item Second Item.
\item Third item. \bf{Different} labels here.
        \begin{enumerate}
        \item First nested item
        \item Second item.
        \end{enumerate}
\end{enumerate}

1.3 Font
Bold Font
\\        %line break
{\bf This is a test}
\textbf{This is a test}
\textsc{This is a test}        %small capital letter
\emph{Emphasize part here}
footnote \footnote{A foot note}        %footnote format


Matlab

whos   and who       % show variables
load file.m              % load m file
vps(pi, 300)                         Display the first 300 digits of pi
p = 'hello world'
x = input('Accept a number: ')   % default is number
y = input('Accept a string', 's')   % accept a string
x = double(char('9'))                 % the ASCII number of '9'


>> for i='a':'z'        % demonstrate the for loop and type cast
double(char(i))
end


A=[1 2 3 4 5]                      Vector
size(A)            1x5
length(A)         length of A
A(3)                the third item of array
disp(A(3))       display the third item of array

A=[1,2,3; 4,5,6; 7,8,9]        Define a matrix
A=[A;[1 2 3]], [1;2;3;4]];    semicolon at the end of the statement suppresses the display of such a matrix.The size of a matrix can be expanded or reduced dynamically.

zeros(4)                  zero matrix square with 4*4
magic(4)                 magic matrix square with 4*4
rand(4)                   4*4 matrix with rand values
randsrc(m,n)           generate a matrix which elements are 1 or -1 with probability
b = A(:,[3])            get the first and last column
c = A(2,:)               get the first row
A'                          Transpose matrix
c = [A;B]               vertically concatenation
c = [A B]               horizontally concatenates
size(A)                   size of a matrix
A = ones(8,7)
A = reshape(A, 14, 4)    The number of elements must be equal

A(2:3,2:3)              2,3 row and 2,3 column
A(1:2:end,:)            get the odd row
A(:,1:2:end)            get the even column
v=[1 2 3]               
A=ones(3,1000)
>> for i=1:1000
A(:,i)=v                  for colume fill
end

>> linspace(F,L,N)    % F start point; L End point; N segments
>> v=F:G:L              % F start point; step size G; L End point

>> x=[1,2,3,4]; y=[1,3,3,0]
>> plot(x,y)
>> axis('equal')      % will use the same scaler on both x-coo and y-coo
>> xlable('x')      
>> ylable('y')
>> title('Title part')
>> hold on            % add more graphs until hold off