Sunday, October 23, 2011

L1 and L2 cache memory

Cache memory is an extremely fast memory that is built into the CPU. The CPU uses cache memory to store instructions and data that are repeatedly required to run programs which helps to improve overall system performance. The advantage of cache memory is that the CPU does not have to use the memory bus(EMIF) for program/data transfer for repeated memory fetches. Whenever data needs to be passed through the memory bus, the data transfer speed slows to the External Memory Interface (EMIF) capability. The CPU can process data much faster by avoiding the bottleneck created by the memory bus.

As it happens, once most programs are open and running, they use very few resources. When these resources are kept in cache, programs can operate more quickly and efficiently. All else being equal, cache is so effective in system performance that a computer running a fast CPU with little cache can have lower benchmarks than a system running a somewhat slower CPU with more cache. Cache built into the CPU itself is referred to as Level 1 (L1) cache. Cache that resides on a separate chip next to the CPU is called Level 2 (L2) cache. Some CPUs have both L1 and L2 cache built-in and designate the separate cache chip as Level 3 (L3) cache.

Usually on DSPs from Texas instruments have both L1 and L2 built-in to CPU. L1 is divided to L1P (Program) and L1D (Data). L1 and L2 are collectively referred as Internal System Memory (ISRAM) due to the reason that you can disable the cache functionality of them and use as Internal memory. This memory is extremely fast than accessing DDR/SDRAM through EMIF bus. IRAM is usually small as few KBs. The maximum I have seen so far is 256 KB.

L1 is the fastest. So it is better to use L1P and L1D separately as this will boost up the performance of the DSP application. L2 is the next fastest (less faster than L1 and a lot more faster than DDR through EMIF). Part of L2 is usually assigned as a cache (32 KB or 64 KB) and the remaining area is used as ISRAM. This area is used to store most critical parts of your code that require fast execution. For example, codes such as FIR, IIR, DCT, DFT are usually stored in ISRAM for fast execution.




----------------------------------------------------------------------------------------------

 A level 2 (L2) cache basically operates in the same manner as a level 1 cache; however, level 2
cache are typically larger in capacity. Level 1 and level 2 caches interact as follows: an address misses in
L1 and is passed on to L2 for handling; L2 employs the same valid bit and tag comparisons to determine if
the requested address is present in L2 cache or not. L1 hits are directly serviced from the L1 caches and
do not require involvement of L2 caches.
As L1P and L1D, the L2 memory space can also be split into an addressable internal memory (L2 SRAM)
and a cache (L2 Cache) portion. Unlike L1 caches that are read – allocate only, L2 cache is a read and
write allocate cache. L2 cache is used to cache external memory addresses only; whereas, L1P and L1D
are used to cache both L2 SRAM and external memory addresses.

 --------------------------------------------------------------------------------------------------

CPU cache is something more complicated than other kind of caches and thus, CPU caches are divided into 2 groups, the Level 1 and Level 2 caches, usually called L1 and L2. A L1 cache is some kind of memory which is built into the same CPU and it is the place where the CPU first try to access. The L2 cache is another memory but instead of feeding the CPU, this one feeds the L1 cache and this way the L2 cache can be understood as a cache of the L1 cache.
L2 caches may be built the same way as the L1 caches, into the CPU but sometimes it can also be located in another chip or in a MCP (Multichip Package Module), it can also be a completely separate chip. With some exceptions, L1 and L2 caches are considered SRAM (static RAM) while the memory of the computer is considered DRAM (Dynamic Ram) or any kind of variation of DRAM. Some processors use another cache level named L3.
The difference between L1 and L2 (and L3 in some cases) is the size. L1 is smaller than L2 and L3. This way the data is easier to be found in the L1 than L2, making the access much faster, if the data is not found in the L1 the data will be looked in the L2 bigger cache and if it is not there, an access to memory will be needed making the access much slower than either to L1 or L2.
The way the caches are managed depends on the architecture of the processors, but there are 2 main methods, inclusive and exclusive. In some processors the data which is stored on the L1 cache will also be present in the L2, this is called inclusive or more technically “strictly inclusive”. The AMD Athlon for example uses an exclusive cache pattern so the data will either be available in the L1 or the L2 but will never be stored in both. Intel Pentium II, III and 4 use a mixed pattern where the data must not be in both of them but usually it is. This is called mainly inclusive policy.
Which method is better is a very complicated question. The exclusive cache method can store more data because the data is not repeated on both of them. The advantage is even greater depending on the size of both caches. The major advantage of inclusive policy is that when other devices or processors in a system with several processors want to delete some data, they only need to check the L2 cache because the data will be also stored in the L1 cache for sure, while the exclusive cache policy will have to check on both the L1 and the L2 cache, making the operation slower.

Sunday, September 18, 2011

Ethernet crossover and Strainght cable

An Ethernet crossover cable is a type of Ethernet cable used to connect computing devices together directly. Normal straight through or patch cables were used to connect from a host network interface controller (a computer or similar device) to a network switch, hub or router. A cable with connections that "cross over" was used to connect two devices of the same type: two hosts or two switches to each other.

T-568A Straight-Through Ethernet Cable
The TIA/EIA 568-A standard which was ratified in 1995, was replaced by the TIA/EIA 568-B standard in 2002 and has been updated since. Both standards define the T-568A and T-568B pin-outs for using Unshielded Twisted Pair cable and RJ-45 connectors for Ethernet connectivity. The standards and pin-out specification appear to be related and interchangeable, but are not the same and should not be used interchangeably.
T-568B Straight-Through Ethernet Cable
Both the T-568A and the T-568B standard Straight-Through cables are used most often as patch cords for your Ethernet connections. If you require a cable to connect two Ethernet devices directly together without a hub or when you connect two hubs together, you will need to use a Crossover cable instead.
RJ-45 Crossover Ethernet Cable
A good way of remembering how to wire a Crossover Ethernet cable is to wire one end using the T-568A standard and the other end using the T-568B standard. Another way of remembering the color coding is to simply switch the Green set of wires in place with the Orange set of wires. Specifically, switch the solid Green (G) with the solid Orange, and switch the green/white with the orange/white.
Ethernet Cable Instructions:
  1. Pull the cable off the reel to the desired length and cut. If you are pulling cables through holes, its easier to attach the RJ-45 plugs after the cable is pulled. The total length of wire segments between a PC and a hub or between two PC's cannot exceed 100 Meters (328 feet) for 100BASE-TX and 300 Meters for 10BASE-T.
  2. Start on one end and strip the cable jacket off (about 1") using a stripper or a knife. Be extra careful not to nick the wires, otherwise you will need to start over.
  3. Spread, untwist the pairs, and arrange the wires in the order of the desired cable end. Flatten the end between your thumb and forefinger. Trim the ends of the wires so they are even with one another, leaving only 1/2" in wire length. If it is longer than 1/2" it will be out-of-spec and susceptible to crosstalk. Flatten and insure there are no spaces between wires.
  4. Hold the RJ-45 plug with the clip facing down or away from you. Push the wires firmly into the plug. Inspect each wire is flat even at the front of the plug. Check the order of the wires. Double check again. Check that the jacket is fitted right against the stop of the plug. Carefully hold the wire and firmly crimp the RJ-45 with the crimper.
  5. Check the color orientation, check that the crimped connection is not about to come apart, and check to see if the wires are flat against the front of the plug. If even one of these are incorrect, you will have to start over. Test the Ethernet cable.
Ethernet Cable Tips:
  • A straight-thru cable has identical ends.
  • A crossover cable has different ends.
  • A straight-thru is used as a patch cord in Ethernet connections.
  • A crossover is used to connect two Ethernet devices without a hub or for connecting two hubs.
  • A crossover has one end with the Orange set of wires switched with the Green set.
  • Odd numbered pins are always striped, even numbered pins are always solid colored.
  • Looking at the RJ-45 with the clip facing away from you, Brown is always on the right, and pin 1 is on the left.
  • No more than 1/2" of the Ethernet cable should be untwisted otherwise it will be susceptible to crosstalk.
  • Do not deform, do not bend, do not stretch, do not staple, do not run parallel with power cables, and do not run Ethernet cables near noise inducing components.
Basic Theory:

By looking at a T-568A UTP Ethernet straight-thru cable and an Ethernet crossover cable with a T-568B end, we see that the TX (transmitter) pins are connected to the corresponding RX (receiver) pins, plus to plus and minus to minus. You can also see that both the blue and brown wire pairs on pins 4, 5, 7, and 8 are not used in either standard. What you may not realize is that, these same pins 4, 5, 7, and 8 are not used or required in 100BASE-TX as well. So why bother using these wires, well for one thing its simply easier to make a connection with all the wires grouped together. Otherwise you'll be spending time trying to fit those tiny little wires into each of the corresponding holes in the RJ-45 connector.


Cross Cable 
Ethernet crossover cables are most often used in home networks when connecting two ethernet computers without a hub. An Ethernet crossover cable has it's send and receive wires crossed.  When using a hub or switch, this is automatically done for you. 



GREEN cables represent standard ethernet cables
BLUE cables represent CROSSOVER cables
No Crossover cable needed
Crossover cable IS needed

Reefered form this link:  http://www.elec-intro.com/ethernet-rj45





Reference link
http://en.wikipedia.org/wiki/Ethernet_crossover_cable

Friday, September 2, 2011

MOST Use Ful commands in Linux / UNIX

1. tar command examples

Create a new tar archive.
$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
$ tar xvf archive_name.tar
View an existing tar archive.
$ tar tvf archive_name.tar
More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples

2. grep command examples

Search for a given string in a file (case in-sensitive search).
$ grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
Search for a given string in all files recursively
$ grep -r "ramesh" *
More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples

3. find command examples

Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"
Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty
More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples

4. ssh command examples

Login to remote host
ssh -l jsmith remotehost.example.com
Debug ssh client
ssh -v -l jsmith remotehost.example.com
Display ssh client version
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
More ssh examples: 5 Basic Linux SSH Client Commands

5. sed command examples

When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename
Print file content in reverse order
$ sed -n '1!G;h;$p' thegeekstuff.txt
Add line number for all non-empty-lines in a file
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'
More sed examples: Advanced Sed Substitution Examples

6. awk command examples

Remove duplicate lines using awk
$ awk '!($0 in array) { array[$0]; print }' temp
Print all lines from /etc/passwd that has the same uid and gid
$awk -F ':' '$3==$4' passwd.txt
Print only specific field from a file.
$ awk '{print $2,$5;}' employee.txt
More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

7. vim command examples

Go to the 143rd line of file
$ vim +143 filename.txt
Go to the first match of the specified
$ vim +/search-term filename.txt
Open the file in read only mode.
$ vim -R /etc/passwd
More vim examples: How To Record and Play in Vim Editor

8. diff command examples

Ignore white space while comparing.
# diff -w name_list.txt name_list_new.txt

2c2,3
< John Doe --- > John M Doe
> Jason Bourne
More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff, Wdiff, Vimdiff

9. sort command examples

Sort a file in ascending order
$ sort names.txt
Sort a file in descending order
$ sort -r names.txt
Sort passwd file by 3rd field.
$ sort -t: -k 3n /etc/passwd | more

10. export command examples

To view oracle related environment variables.
$ export | grep ORACLE
declare -x ORACLE_BASE="/u01/app/oracle"
declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"
declare -x ORACLE_SID="med"
declare -x ORACLE_TERM="xterm"
To export an environment variable:
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0

11. xargs command examples

Copy all images to external hard-drive
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Search all jpg images in the system and archive it.
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Download all the URLs mentioned in the url-list.txt file
# cat url-list.txt | xargs wget –c

12. ls command examples

Display filesize in human readable format (e.g. KB, MB etc.,)
$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
Visual Classification of Files With Special Characters Using ls -F
$ ls -F
More ls examples: Unix LS Command: 15 Practical Examples

13. pwd command

pwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.

14. cd command examples

Use “cd -” to toggle between the last two directories
Use “shopt -s cdspell” to automatically correct mistyped directory names on cd
More cd examples: 6 Awesome Linux cd command Hacks

15. gzip command examples

To create a *.gz compressed file:
$ gzip test.txt
To uncompress a *.gz file:
$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
         compressed        uncompressed  ratio uncompressed_name
              23709               97975  75.8% asp-patch-rpms.txt

16. bzip2 command examples

To create a *.bz2 compressed file:
$ bzip2 test.txt
To uncompress a *.bz2 file:
bzip2 -d test.txt.bz2
More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples

17. unzip command examples

To extract a *.zip compressed file:
$ unzip test.zip
View the contents of *.zip file (Without unzipping it):
$ unzip -l jasper.zip
Archive:  jasper.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    40995  11-30-98 23:50   META-INF/MANIFEST.MF
    32169  08-25-98 21:07   classes_
    15964  08-25-98 21:07   classes_names
    10542  08-25-98 21:07   classes_ncomp

18. shutdown command examples

Shutdown the system and turn the power off immediately.
# shutdown -h now
Shutdown the system after 10 minutes.
# shutdown -h +10
Reboot the system using shutdown command.
# shutdown -r now
Force the filesystem check during reboot.
# shutdown -Fr now

19. ftp command examples

Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.
$ ftp IP/hostname
ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as shown below.
ftp> mls *.html -
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html
More ftp examples: FTP and SFTP Beginners Guide with 10 Examples

20. crontab command examples

View crontab entry for a specific user
# crontab -u john -l
Schedule a cron job every 10 minutes.
*/10 * * * * /home/ramesh/check-disk-space
More crontab examples: Linux Crontab: 15 Awesome Cron Job Examples

21. service command examples

Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.
Check the status of a service:
# service ssh status
Check the steatus of all the services.
service --status-all
Restart a service.
# service ssh restart

22. ps command examples

ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some of the common ones.
To view current running processes.
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more

23. free command examples

This command is used to display the free, used, swap memory available in the system.
Typical free command output. The output is displayed in bytes.
$ free
             total       used       free     shared    buffers     cached
Mem:       3566408    1580220    1986188          0     203988     902960
-/+ buffers/cache:     473272    3093136
Swap:      4000176          0    4000176
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.
$ free -g
             total       used       free     shared    buffers     cached
Mem:             3          1          1          0          0          0
-/+ buffers/cache:          0          2
Swap:            3          0          3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
ramesh@ramesh-laptop:~$ free -t
             total       used       free     shared    buffers     cached
Mem:       3566408    1592148    1974260          0     204260     912556
-/+ buffers/cache:     475332    3091076
Swap:      4000176          0    4000176
Total:     7566584    1592148    5974436

24. top command examples

top command displays the top processes in the system ( by default sorted by cpu usage ). To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.
Current Sort Field:  P  for window 1:Def
Select sort field via field letter, type any other key to return

  a: PID        = Process Id              v: nDRT       = Dirty Pages count
  d: UID        = User Id                 y: WCHAN      = Sleeping in Function
  e: USER       = User Name               z: Flags      = Task Flags
  ........
To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.
$ top -u oracle
More top examples: Can You Top This? 15 Practical Linux Top Command Examples

25. df command examples

Displays the file system disk space usage. By default df -k displays output in bytes.
$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             29530400   3233104  24797232  12% /
/dev/sda2            120367992  50171596  64082060  44% /home
df -h displays output in human readable form. i.e size will be displayed in GB’s.
ramesh@ramesh-laptop:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G  3.1G   24G  12% /
/dev/sda2             115G   48G   62G  44% /home
Use -T option to display what type of file system.
ramesh@ramesh-laptop:~$ df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext4    29530400   3233120  24797216  12% /
/dev/sda2     ext4   120367992  50171596  64082060  44% /home

26. kill command examples

Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.
$ ps -ef | grep vim
ramesh    7243  7222  9 22:43 pts/2    00:00:00 vim

$ kill -9 7243
More kill examples: 4 Ways to Kill a Process – kill, killall, pkill, xkill

27. rm command examples

Get confirmation before removing the file.
$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.
Print the filename and get confirmation before removing the file.
$ rm -i file*
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.
$ rm -r example

28. cp command examples

Copy file1 to file2 preserving the mode, ownership and timestamp.
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2

29. mv command examples

Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.
$ mv -v file1 file2

30. cat command examples

You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.
$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf
    1	/var/log/btmp {
    2	    missingok
    3	    monthly
    4	    create 0660 root utmp
    5	    rotate 1
    6	}

31. mount command examples

To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01

# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2

32. chmod command examples

chmod command is used to change the permissions for a file or directory.
Give full access to user and group (i.e read, write and execute ) on a specific file.
$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) on a specific file.
$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt
More chmod examples: 7 Chmod Command Examples for Beginners

33. chown command examples

chown command is used to change the owner and group of a file. \
To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.
$ chown oracle:dba dbora.sh
Use -R to change the ownership recursively.
$ chown -R oracle:dba /home/oracle

34. passwd command examples

Change your password from command line using passwd. This will prompt for the old password followed by the new password.
$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.
# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.
# passwd -d USERNAME

35. mkdir command examples

Following example creates a directory called temp under your home directory.
$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesn’t exist, it will create them.
$ mkdir -p dir1/dir2/dir3/dir4/

36. ifconfig command examples

Use ifconfig command to view or configure a network interface on the Linux system.
View all the interfaces along with status.
$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up

$ ifconfig eth0 down
More ifconfig examples: Ifconfig: 7 Examples To Configure Network Interface

37. uname command examples

Uname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,
Sample uname output from a Ubuntu laptop is shown below.
$ uname -a
Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux

38. whereis command examples

When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other than the whereis default path, you can use -B option and give path as argument to it. This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.
$ whereis -u -B /tmp -f lsmk
lsmk: /tmp/lsmk

39. whatis command examples

Whatis command displays a single line description about a command.
$ whatis ls
ls		(1)  - list directory contents

$ whatis ifconfig
ifconfig (8)         - configure a network interface

40. locate command examples

Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb.
The example below shows all files in the system that contains the word crontab in it.
$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim

41. man command examples

Display the man page of a specific command.
$ man crontab
When a man page for a command is located under more than one section, you can view the man page for that command from a specific section as shown below.
$ man SECTION-NUMBER commandname
Following 8 sections are available in the man page.
  1. General commands
  2. System calls
  3. C library functions
  4. Special files (usually devices, those found in /dev) and drivers
  5. File formats and conventions
  6. Games and screensavers
  7. Miscellaneous
  8. System administration commands and daemons
For example, when you do whatis crontab, you’ll notice that crontab has two man pages (section 1 and section 5). To view section 5 of crontab man page, do the following.
$ whatis crontab
crontab (1)          - maintain crontab files for individual users (V3)
crontab (5)          - tables for driving cron

$ man 5 crontab

42. tail command examples

Print the last 10 lines of a file by default.
$ tail filename.txt
Print N number of lines from the file named filename.txt
$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.
$ tail -f log-file
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One Terminal

43. less command examples

less is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.
$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.
CTRL+F – forward one window
CTRL+B – backward one window
More less examples: Unix Less Command: 10 Tips for Effective Navigation

44. su command examples

Switch to a different user account using su command. Super user can switch to any other user without entering their password.
$ su - USERNAME
Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to john’s account.
[john@dev-server]$ su - raj -c 'ls'

[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.
$ su -s 'SHELLNAME' USERNAME

45. mysql command examples

mysql is probably the most widely used open source database on Linux. Even if you don’t run a mysql database on your server, you might end-up using the mysql command ( client ) to connect to a mysql database running on the remote server.
To connect to a remote mysql database. This will prompt for a password.
$ mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.
$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).

46. yum command examples

To install apache using yum.
$ yum install httpd
To upgrade apache using yum.
$ yum update httpd
To uninstall/remove apache using yum.
$ yum remove httpd

47. rpm command examples

To install apache using rpm.
# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.
# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.
# rpm -ev httpd
More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages

48. ping command examples

Ping a remote host by sending only 5 packets.
$ ping -c 5 gmail.com
More ping examples: Ping Tutorial: 15 Effective Ping Command Examples

49. date command examples

Set the system date:
# date -s "01/31/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.
# hwclock –systohc

# hwclock --systohc –utc

50. wget command examples

The quick and effective method to download software, music, video from internet is using wget command.
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
Download and store it with a different name.
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

How to extra iso file

su
Password:
mkdir mountpoint
mount -o loop YourImage.iso mountpoint
ls mountpoint/

Wednesday, August 24, 2011

Latex HOME

 How to install Latex

 Linux
In Fedora
  •  yum install kile
  •  Type kile in terminal 
  •  file ->new file-> copy demo code -> run as pdf
In ubuntu 
  • apt-get install kile
  • Type kile in terminal  
  •  file ->new file-> copy demo code -> run as pdf 

 Window

You’ll need three things:


Step 1:Install  MiKTeX 2.9 Net Installer
Step 2 :Install    TeXnicCenter and  Foxit Reader.
Setp 3:Start TeXnicCenter. Open a New Document and copy/paste the sample code from below.
          Save it as a .tex file and change the output profile (pdflatex) .
Step4:Run 




Sample Code:

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\begin{document}

\title{Introduction to \LaTeX{}}
\author{Your Name}
\date{\today}
\maketitle

\begin{abstract}
The abstract text goes here.
\end{abstract}

\section{Introduction}
Here is the text of your introduction.

$\alpha = \sqrt{ \beta }$ %inline equation

  \[ \sum_{i=0}^{n-1}n^2
     \] % big equation

\subsection{Subsection Heading Here}
Write your subsection text here.

\section{Conclusion}
Write your conclusion here.

\end{document}


Document how to write



\documentclass{book, report, article or letter}

 http://texblog.wordpress.com/2007/07/09/documentclassbook-report-article-or-letter/

A LaTeX document starts with the command \documentclass [option] {type}. The most common document-classes in LaTex are:
  1. book
  2. report
  3. article
  4. letter
All of them are similar, except letter. The main differences can be summerised as follows:
  • An “article” does not provide “chapter”, whereas “book” and “report” do. Thus, the first structuring element of an “article” is \section{name}.
  • In a “book”, a header is automatically added to each page indicating the page number as well as the chapter name on even pages and the section name on odd pages
  • A “book” is always 2-sided whereas in a “report” or “article” you have to specify it by using the “twoside” option. In addition, in a “book” and “report” the “titlepage” and “abstract” will take a whole page each, which is not the case for “article”. In an “article”, you can use the options “titlepage” and “abstract”.
  • The “letter” provides a US-type letter format.
Available document structure commands:

Book: \part{}, \chapter{}, \section{}, \subsection{}, \subsubsection{}, \paragraph{}, \subparagraph{}.
Report: \part{}, \chapter{}, \section{}, \subsection{}, \subsubsection{}, \paragraph{}, \subparagraph{}.
Article: \part{}, \section{}, \subsection{}, \subsubsection{}, \paragraph{}, \subparagraph{}.
Letter: A letter does not know the same structuring commands as other formats, but more specific commands like \signature{}, \address{}, \opening{} and \closing{}.
Except \part{}, all structuring commands build a hierarchy. They have a standard formating and numeration.














 for sub figure
http://texblog.wordpress.com/2007/08/28/placing-figurestables-side-by-side-subfigure/

\usepackage{subfigure}
Once the package is included, you can start using the environment.

\begin{figure}[ht]
\centering
\subfigure[Caption of subfigure 1]{
\includegraphics[scale=1]{subfigure1.eps}
\label{fig:subfig1}
}
\subfigure[Caption of subfigure 2]{
\includegraphics[scale=1]{subfigure2.eps}
\label{fig:subfig2}
}
\subfigure[Caption of subfigure 3]{
\includegraphics[scale=1]{subfigure3.eps}
\label{fig:subfig3}
}
\label{fig:subfigureExample}
\caption[Optional caption for list of figures]{Caption of subfigures \subref{fig:subfig1}, \subref{fig:subfig2} and \subref{fig:subfig3}}
\end{figure}

more on figure
http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

Quote-marks

http://en.wikibooks.org/wiki/LaTeX/Formatting

Latex treats left and right quotes as different entities. For single quotes, ` (on American keyboards, this symbol is found on the tilde key (adjacent to the number 1 key on most) gives a left quote mark, and ' is the right. For double quotes, simply double the symbols, and Latex will interpret them accordingly. (Although, you can use the " for right double quotes if you wish). On British keyboards, ' ` ' is left of the ' 1 ' key and shares the key with ' ¬ ', and sometimes ' ¦ ' or ' | '. The apostrophe (' ' ') key is to the right of the colon/semicolon key and shares it with the ' @ ' symbol.

To `quote' in Latex Quote1.png
To ``quote'' in Latex Quote2.png
To ``quote" in Latex Quote2.png
To ,,quote'' in Latex Quote4.png
``Please press the `x' key.'' Latex quote 3.png
,,Proszę, naciśnij klawisz <<x>>''. Latex quote 4.png














Text mode superscript and subscript

To superscript text in text-mode, you can use the \textsuperscript{} command. This allows you to, for instance, typeset 6th as 6th:
Michelangelo was born on March 6\textsuperscript{th}, 1475.
A very common use of subscripts within the text environment is to typeset chemical formulae. For this purposes, a highly recommended package is mhchem. This package is easy to use, and works with your text fonts (rather than math fonts). To insert a chemical formula, use \ce{} with the text-equivalent formula, for example:
% In your preamble, add:
\usepackage[version=3]{mhchem}
...

% In your document:
Ammonium sulphate is \ce{(NH4)2SO4}.
Ammonium sulphate mhchem.png

Subscripting in text-mode is not supported by LaTeX alone; however, several packages allow the use of the \textsubscript{} command. For instance, bpchem, KOMA-Script2, and fixltx2e all support this command. Of these, fixltx2e is perhaps the most universal option since it is distributed with LaTeX and requires no additional packages to be implemented.
% In your preamble, add:
\usepackage{fixltx2e}
...

% In your document:
It is found that height\textsubscript{apple tree} is
different than height\textsubscript{orange tree
}.
\text{It is found that height}_\text{apple tree}\text{ is different than height}_\text{orange tree}\text{.}\,
If you do not load a package that supports \textsubscript{}, the math mode must be used. This is easily accomplished in running text by bracketing your text with the $ symbol. In math mode subscripting is done using the underscore: _{}.
For example, the formula for water is written as:
H$_2$O is the formula for water H2O is the formula for water
See also the above mentioned package mhchem for chemical symbols and formulas.
Note that in math mode text will appear in a font suitable for mathematical variables. In math mode, to generate roman text, for example, one would use the \mathrm command:
This is $\mathrm{normal\ roman\ and}_\mathrm{subscript\ roman}$ text \text{This is }\mathrm{normal\ roman\ and}_\mathrm{subscript\ roman}\text{  text}
Note the use of \<space> to insert a space in math mode.
Similarly, you can superscript using:
This is $\mathrm{normal\ roman\ and}^\mathrm{superscript\ roman}$ text \text{This is }\mathrm{normal\ roman\ and}^\mathrm{superscript\ roman}\text{  text}

[edit] Text figures ("old style" numerals)


Beamer help
http://www.uncg.edu/cmp/reu/presentations/Charles%20Batts%20-%20Beamer%20Tutorial.pdf



\begin{frame}[allowframebreaks]{Outline}
The above code will split any over hang across multiple slides.
 
 \begin{frame}[shrink]{Outline}
The above will try to shrink content to fit frame margins.

You can divide your presentations in parts with
\part{1} .... \part{n}
then you can show the toc of every part on an other slide with
\tableofcontents[part=1]
If you use
\tableofcontents[currentsection]
only the toc of the part will be displayed...

Symbols

http://www.andy-roberts.net/writing/latex/formatting

Table of text symbols and
  their LaTeX commands

 image showing various font
  styles available in LaTeX
Various font sizes available
  in LaTeX: commands and their respective sizes



mathe 
ftp://ftp.ams.org/ams/doc/amsmath/short-math-guide.pdf



most correct answer    Wiki latex
http://en.wikibooks.org/wiki/LaTeX/Tables



 package, include:
\usepackage{amsmath}
or
\usepackage{mathtools}
in the preamble of the document.

 Mathematics environments

LaTeX needs to know beforehand that the subsequent text does in fact contain mathematical elements. This is because LaTeX typesets maths notation differently than normal text. Therefore, special environments have been declared for this purpose. They can be distinguished into two categories depending on how they are presented:
  • text - text formulas are displayed in-line, that is, within the body of text where it is declared. e.g., I can say that a + a = 2a within this sentence.
  • displayed - displayed formulas are separate from the main text.
As maths require special environments, there are naturally the appropriate environment names you can use in the standard way. Unlike most other environments, however, there are some handy shorthands to declaring your formulas. The following table summarizes them:
Type Environment LaTeX shorthand TeX shorthand
Text \begin{math}...\end{math} \(...\) $...$
Displayed \begin{displaymath}...\end{displaymath} or \begin{equation*}...\end{equation*}[3] \[...\] $$...$$

In order for some operators, such as \lim or \sum to be displayed correctly inside some math environments (read $......$), it might be convenient to write the \displaystyle class inside the environment. Doing so might cause the line to be taller, but will cause exponents and indices to be displayed correctly for some math operators. For example, the $\sum$ will print a smaller Σ and $\displaystyle \sum$ will print a bigger one \displaystyle \sum, like in equation (This only works with AMSMATH package).

Symbols

Mathematics has lots and lots of symbols! If there is one aspect of maths that is difficult in LaTeX it is trying to remember how to produce them. There are of course a set of symbols that can be accessed directly from the keyboard:
+ - = ! / ( ) [ ] < > | ' :
Beyond those listed above, distinct commands must be issued in order to display the desired symbols. And there are a lot! of Greek letters, set and relations symbols, arrows, binary operators, etc. For example:
\[
 \forall x \in X, \quad \exists y \leq \epsilon
\
]
\forall x \in X, \quad \exists y \leq \epsilon
 \,
Fortunately, there's a tool that can greatly simplify the search for the command for a specific symbol. Look for "Detexify" in the external links section below. Another option would be to look in the "The Comprehensive LaTeX Symbol List" in the external links section below.

Greek letters

Greek letters are commonly used in mathematics, and they are very easy to type in math mode. You just have to type the name of the letter after a backslash: if the first letter is lowercase, you will get a lowercase Greek letter, if the first letter is uppercase (and only the first letter), then you will get an uppercase letter. Note that some uppercase Greek letters look like Latin ones, so they are not provided by LaTeX (e.g. uppercase Alpha and Beta are just "A" and "B" respectively). Lowercase epsilon, theta, phi, pi, rho, and sigma are provided in two different versions. The alternate, or variant, version is created by adding "var" before the name of the letter:
\[
  \alpha, \Alpha, \beta, \Beta, \gamma, \Gamma,
  \pi, \Pi, \phi, \varphi, \Phi
\
]
α,Α,β,Β,γ,Γ,π,Π,ϕ,φ,Φ
Scroll down to #List_of_Mathematical_Symbols for a complete list of Greek symbols.

Operators

An operator is a function that is written as a word: e.g. trigonometric functions (sin, cos, tan), logarithms and exponentials (log, exp). LaTeX has many of these defined as commands:
\[
 \cos (2\theta) = \cos^2 \theta - \sin^2 \theta
\
]
\cos (2\theta) = \cos^2 \theta - \sin^2 \theta \,
For certain operators such as limits, the subscript is placed underneath the operator:
\[
 \lim_{x \to \infty} \exp(-x) = 0
\
]
\lim_{x \to \infty} \exp(-x) = 0
For the modular operator there are two commands: \bmod and \pmod:
\[
 a \bmod b
\
]
 a \, \bmod \, b
\,
\[
 x \equiv a \pmod b
\
]
 x \equiv a \pmod b
\,


Powers and indices

Powers and indices are equivalent to superscripts and subscripts in normal text mode. The caret (^) character is used to raise something, and the underscore (_) is for lowering. If more than one expression is raised or lowered, they should be grouped using curly braces ({ and }).
\[
 k_{n+1} = n^2 + k_n^2 - k_{n-1}
\
]
k_{n+1} = n^2 + k_n^2 - k_{n-1}
 \,
An underscore (_) can be used with a vertical bar ( | ) to denote evaluation using subscript notation in mathematics:
\[
 f(n) = n^5 + 4n^2 + 2 |_{n=17}
\
]
 f(n) = n^5 + 4n^2 + 2 |_{n=17}
 \,

Fractions and Binomials

A fraction is created using the \frac{numerator}{denominator} command. (for those who need their memories refreshed, that's the top and bottom respectively!)
\[
 \frac{n!}{k!(n-k)!} = \binom{n}{k}
\
]
\frac{n!}{k!(n-k)!} = \binom{n}{k}
It is also possible to use the \choose command without the amsmath package:
\[
 \frac{n!}{k!(n-k)!} = {n \choose k}
\
]
 \frac{n!}{k!(n-k)!} = {n \choose k}
You can embed fractions within fractions:
\[
 \frac{\frac{1}{x}+\frac{1}{y}}{y-z}
\
]
\frac{\frac{1}{x}+\frac{1}{y}}{y-z}
Note that when appearing inside another fraction, or in inline text \tfrac{a}{b}, a fraction is noticeably smaller than in displayed mathematics. The \tfrac and \dfrac commands[3] force the use of the respective styles, \textstyle and \displaystyle. Similarly, the \tbinom and \dbinom commands typeset the binomial coefficient.
Another way to write fractions is to use the \over command without the amsmath package:
\[
 {n! \over k!(n-k)!} = {n \choose k}
\
]
 {n! \over k!(n-k)!} = {n \choose k}
For relatively simple fractions, it may be more aesthetically pleasing to use powers and indices:
\[
 ^3/_7
\
]
^3/_7
 \,
If you use them throughout the document, usage of xfrac package is recommended. This package provides \sfrac command to create slanted fractions. Usage:
Take \sfrac{1}{2} cup of sugar, \dots
 \[
  3\times\sfrac{1}{2}=1\sfrac{1}{2}
 \
]

Take ${}^1/_2$ cup of sugar, \dots
 \[
  3\times{}^1/_2=1{
}^1/_2
 \
]
LaTeX-xfrac-example.png
Alternatively, the nicefrac package provides the \nicefrac command, whose usage is similar to \sfrac.

Continued fractions

Continued fractions should be written using \cfrac command[3]:
\begin{equation}
  x = a_0 + \cfrac{1}{a_1
          + \cfrac{1}{a_2
          + \cfrac{1}{a_3 + a_4}}}
\end{equation
}
   x = a_0 + \cfrac{1}{a_1 
           + \cfrac{1}{a_2 
           + \cfrac{1}{a_3 + a_4}}}

Multiplication of two numbers

To make multiplication visually similar to a fraction, you can use nested array. Multiplication of numbers written one behalf other.
\begin{equation}
\frac{
    \begin{array}[b]{r}
      \left( x_1 x_2 \right)\\
      \times \left( x'_1 x'_2 \right)
    \end{array}
  }{
    \left( y_1y_2y_3y_4 \right)
  }
\end{equation
}
\frac{
    \begin{array}[b]{r}
      \left( x_1 x_2 \right)\\
      \times \left( x'_1 x'_2 \right)
    \end{array}
  }{
    \left( y_1y_2y_3y_4 \right)
  }

Roots

The \sqrt command creates a square root surrounding an expression. It accepts an optional argument specified in square brackets ([ and ]) to change magnitude:
\[
\sqrt{\frac{a}{b}}
\
]
\sqrt{\frac{a}{b}}
\[
\sqrt[n
]{1+x+x^2+x^3+\ldots}
\]
\sqrt[n]{1+x+x^2+x^3+\ldots}

Some people prefer writing the square root "closing" it over its content. This method arguably makes it more clear just what is in the scope of the root sign. This habit is not normally used while writing with the computer, but if you still want to change the output of the square root, LaTeX gives you this possibility. Just add the following code in the preamble of your document:
% New definition of square root:
% it renames \sqrt as \oldsqrt
\let\oldsqrt\sqrt
% it defines the new \sqrt in terms of the old one
\def\sqrt{\mathpalette\DHLhksqrt}
\def\DHLhksqrt#1#2{%
\setbox0=\hbox{$#1\oldsqrt{#2\,}$}\dimen0=\ht0
\advance\dimen0-0.2\ht0
\setbox2=\hbox{\vrule height\ht0 depth -\dimen0
}%
{\box0\lower0.4pt\box2}}

The new style is on left, the old one on right
This TeX code first renames the \sqrt command as \oldsqrt, then redefines \sqrt in terms of the old one, adding something more. The new square root can be seen in the picture on the right, compared to the old one. Unfortunately this code won't work if you want to use multiple roots: if you try to write \sqrt[b]{a} as \sqrt[b]{a} after you used the code above, you'll just get a wrong output. In other words, you can redefine the square root this way only if you are not going to use multiple roots in the whole document.

Sums and integrals

The \sum and \int commands insert the sum and integral symbols respectively, with limits specified using the caret (^) and underscore (_). The typical notation for sums is:
\[
 \sum_{i=1}^{10} t_i
\
]
\sum_{i=1}^{10} t_i 
 \,
The limits for the integrals follow the same notation. It's also important to represent the integration variables with an upright d, which in math mode is obtained through the \mathrm{} command, and with a small space separating it from the integrand, which is attained with the \, command.
\[
 \int_0^\infty e^{-x}\,\mathrm{d}x
\
]
\int_0^\infty e^{-x}\,\mathrm{d}x
 \,
There are many other "big" commands which operate in a similar manner:
\sum \sum \,
\prod \prod
\coprod \coprod
\bigoplus \bigoplus
\bigotimes \bigotimes
\bigodot \bigodot
\bigcup \bigcup
\bigcap \bigcap
\biguplus \biguplus
\bigsqcup \bigsqcup
\bigvee \bigvee
\bigwedge \bigwedge
\int \int
\oint \oint
\iint[3] \iint
\iiint[3] \iiint
\iiiint[3] \iiiint
\idotsint[3] \int \! \cdots \! \int
For more integral symbols, including those not included by default in the Computer Modern font, try the esint package.
The \substack command[3] allows the use of \\ to write the limits over multiple lines:
\[
 \sum_{\substack{
   0<i<m \\
   0<j<n
  }
}
 P(i,j)
\
]
\sum_{\overset{\scriptstyle 0<i<m} {\scriptstyle 0<j<n}} P(i,j)
 \,
If you want the limits of an integral to be specified above and below the symbol (like the sum), use the \limits command:
\[
 \int\limits_a^b
\
]
\int\limits_a^b
 \,
However if you want this to apply to ALL integrals, it is preferable to specify the intlimits option when loading the amsmath package:
\usepackage[intlimits]{amsmath}
Subscripts and superscripts in other contexts as well as other parameters to amsmath package related to them are described in Advanced Mathematics chapter.
For bigger integrals, you may use personal declarations, or the bigints package [4].

Brackets, braces and delimiters

How to use braces in multi line equations is described in the Advanced Mathematics chapter.
The use of delimiters such as brackets soon becomes important when dealing with anything but the most trivial equations. Without them, formulas can become ambiguous. Also, special types of mathematical structures, such as matrices, typically rely on delimiters to enclose them.
There are a variety of delimiters available for use in LaTeX:
\[
 () \, [
] \, \{\} \, || \, \|\| \,
 \langle\rangle \, \lfloor\rfloor \, \lceil\rceil
\
]
() \, [] \, \{\} \, || \, \|\| \, \langle\rangle \, \lfloor\rfloor \, \lceil\rceil
 \,

Automatic sizing

Very often mathematical features will differ in size, in which case the delimiters surrounding the expression should vary accordingly. This can be done automatically using the \left and \right commands. Any of the previous delimiters may be used in combination with these:
\[
 \left(\frac{x^2}{y^3}\right)
\
]
\left(\frac{x^2}{y^3}\right)
 \,
Curly braces are defined differently by using \left\{ and \right\},
\[
 \left\{\frac{x^2}{y^3}\right\}
\
]
\left\{\frac{x^2}{y^3}\right\}
 \,
If a delimiter on only one side of an expression is required, then an invisible delimiter on the other side may be denoted using a period (.).
\[
 \left.\frac{x^3}{3}\right|_0^1
\
]
 \left.\frac{x^3}{3}\right|_0^1
 \,

Manual sizing

In certain cases, the sizing produced by the \left and \right commands may not be desirable, or you may simply want finer control over the delimiter sizes. In this case, the \big, \Big, \bigg and \Bigg modifier commands may be used:
\[
 ( \big( \Big( \bigg( \Bigg(
\
]
( \big( \Big( \bigg( \Bigg( 
 \,

Matrices and arrays

A basic matrix may be created using the matrix environment[3]: in common with other table-like structures, entries are specified by row, with columns separated using an ampersand (&) and a new rows separated with a double backslash (\\)
\[
 \begin{matrix}
  a & b & c \\
  d & e & f \\
  g & h & i
 \end{matrix
}
\
]
\begin{matrix}
a & b & c \\
d & e & f \\
g & h & i
\end{matrix}
To specify alignment of columns in the table, use starred version[5]:
\[
 \begin{matrix}
  -1 & 3 \\
  2 & -4
 \end{matrix}
 =
 \begin{matrix*}[r
]
  -1 & 3 \\
  2 & -4
 \end{matrix*
}
\]
 \begin{matrix}
  -1 & 3 \\
  2 & -4
 \end{matrix}
 =
 \begin{matrix}
  -1 & \,\;\;3 \\
  \,\;\;2 & -4
 \end{matrix}
The alignment by default is c but it can be any column type valid in array environment.
However matrices are usually enclosed in delimiters of some kind, and while it is possible to use the \left and \right commands, there are various other predefined environments which automatically include delimiters:
Environment name Surrounding delimiter Notes
pmatrix[3] ( \, ) centers columns by default
pmatrix*[5] ( \, ) allows to specify alignment of columns in optional parameter
bmatrix[3] [ \, ] centers columns by default
bmatrix*[5] [ \, ] allows to specify alignment of columns in optional parameter
Bmatrix[3] \{ \, \} centers columns by default
Bmatrix*[5] \{ \, \} allows to specify alignment of columns in optional parameter
vmatrix[3] | \, | centers columns by default
vmatrix*[5] | \, | allows to specify alignment of columns in optional parameter
Vmatrix[3] \| \, \| centers columns by default
Vmatrix*[5] \| \, \| allows to specify alignment of colums in optional parameter
When writing down arbitrary sized matrices, it is common to use horizontal, vertical and diagonal triplets of dots (known as ellipses) to fill in certain columns and rows. These can be specified using the \cdots, \vdots and \ddots respectively:
\[
 A_{m,n} =
 \begin{pmatrix}
  a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
  a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
  \vdots  & \vdots  & \ddots & \vdots  \\
  a_{m,1} & a_{m,2} & \cdots & a_{m,n}
 \end{pmatrix
}
\
]
A_{m,n} = 
\begin{pmatrix}
a_{1,1} & a_{1,2} & \cdots & a_{1,n} \\
a_{2,1} & a_{2,2} & \cdots & a_{2,n} \\
\vdots  & \vdots  & \ddots & \vdots  \\
a_{m,1} & a_{m,2} & \cdots & a_{m,n} 
\end{pmatrix}
In some cases you may want to have finer control of the alignment within each column, or want to insert lines between columns or rows. This can be achieved using the array environment, which is essentially a math-mode version of the tabular environment, which requires that the columns be pre-specified:
\[
 \begin{array}{c|c}
  1 & 2 \\
  \hline
  3 & 4
 \end{array
}
\
]
\begin{array}{c|c}
1 & 2 \\ 
\hline
3 & 4
\end{array}
You may see that the AMS matrix class of environments doesn't leave enough space when used together with fractions resulting in output similar to this:
 M = \begin{bmatrix}
       \frac{5}{6} & \frac{1}{6} & 0\\
       \frac{5}{6} & 0           & \frac{1}{6}\\
       0           & \frac{5}{6} & \frac{1}{6}
     \end{bmatrix}
To counteract this problem, add additional leading space with the optional parameter to the \\ command:
\[
 M = \begin{bmatrix}
       \frac{5}{6} & \frac{1}{6} & 0           \\[0.3em
]
       \frac{5}{6} & 0           & \frac{1}{6} \\[0.3em]
       0           & \frac{5}{6} & \frac{1}{6}
     \end{bmatrix
}
\]
 M = \begin{bmatrix}
       \frac{5}{6} & \frac{1}{6} & 0           \\[0.3em]
       \frac{5}{6} & 0           & \frac{1}{6} \\[0.3em]
       0           & \frac{5}{6} & \frac{1}{6}
     \end{bmatrix}
If you need "border" or "indexes" on your matrix, plain TeX provides the macro \bordermatrix
\[
M = \bordermatrix{~ & x & y \cr
                  A & 1 & 0 \cr
                  B & 0 & 1 \cr
}
\
]
Bordermatrix.png

Matrices in running text

To insert a small matrix, and not increase leading in the line containing it, use smallmatrix environment:
A matrix in text must be set smaller
$\bigl(\begin{smallmatrix}
a&b\\ c&d
\end{smallmatrix
} \bigr)$

to not increase leading in a portion of text.
LaTeX-smallmatrix.png

Adding text to equations

The math environment differs from the text environment in the representation of text. Here is an example of trying to represent text within the math environment:
\[
 50 apples \times 100 apples = lots of apples^2
\
]
 50 apples \times 100 apples = lots of apples^2
\,
There are two noticeable problems: there are no spaces between words or numbers, and the letters are italicized and more spaced out than normal. Both issues are simply artifacts of the maths mode, in that it treats it as a mathematical expression: spaces are ignored (LaTeX spaces mathematics according to its own rules), and each character is a separate element (so are not positioned as closely as normal text).
There are a number of ways that text can be added properly. The typical way is to wrap the text with the \text{...} command (a similar command is \mbox{...}, though this causes problems with subscripts, and has a less descriptive name). Let's see what happens when the above equation code is adapted:
\[
 50 \text{apples} \times 100 \text{apples}
 = \text{lots of apples
}^2
\
]
 50 \text{apples} \times 100 \text{apples} = \text{lots of apples}^2
\,
The text looks better. However, there are no gaps between the numbers and the words. Unfortunately, you are required to explicitly add these. There are many ways to add spaces between maths elements, but for the sake of simplicity you may literally add the space character in the affected \text(s) itself (just before the text.)
\[
 50 \text{ apples} \times 100 \text{ apples}
 = \text{lots of apples
}^2
\
]
 50 \text{ apples} \times 100 \text{ apples} = \text{lots of apples}^2
\,

Formatted text

Using the \text is fine and gets the basic result. Yet, there is an alternative that offers a little more flexibility. You may recall the introduction of font formatting commands, such as \textrm, \textit, \textbf, etc. These commands format the argument accordingly, e.g., \textbf{bold text} gives bold text. These commands are equally valid within a maths environment to include text. The added benefit here is that you can have better control over the font formatting, rather than the standard text achieved with \text.
\[
 50 \textrm{ apples} \times 100
 \textbf{ apples} = \textit{lots of apples
}^2
\
]
 50 \;\textrm{ apples} \times 100 \;\textbf{ apples} = \textit{lots}\;of\;apples^2
\,

To bold lowercase Greek or other symbols use the \boldsymbol command[3]; this will only work if there exists a bold version of the symbol in the current font. As a last resort there is the \pmb command[3] (poor mans bold): this prints multiple versions of the character slightly offset against each other
\[
 \boldsymbol{\beta} = (\beta_1,\beta_2,\ldots,\beta_n)
\
]
 \boldsymbol{\beta} = (\beta_1,\beta_2,\ldots,\beta_n)
\,
To change the size of the fonts in math mode,

Accents

So what to do when you run out of symbols and fonts? Well the next step is to use accents:
a' a'\,
a'' a''\,
a''' a'''\,
a'''' a''''\,
\hat{a} \hat{a} \,
\bar{a} \bar{a} \,
\overline{aaa} \overline{aaa} \,
\check{a} \check{a} \,
\tilde{a} \tilde{a} \,
\grave{a} \grave{a} \,
\acute{a} \acute{a} \,
\breve{a} \breve{a} \,
\vec{a} \vec{a} \,
\dot{a} \dot{a} \,
\ddot{a} \ddot{a} \,
\dddot{a}[3]

\ddddot{a}[3]
\not{a} \not{a} \,
\mathring{a}

\widehat{AAA} \widehat{AAA} \,
\widetilde{AAA}

Plus and minus signs

Latex deals with the + and − signs in two possible ways. The most common is as a binary operator. When two maths elements appear either side of the sign, it is assumed to be a binary operator, and as such, allocates some space either side of the sign. The alternative way is a sign designation. This is when you state whether a mathematical quantity is either positive or negative. This is common for the latter, as in maths, such elements are assumed to be positive unless a − is prefixed to it. In this instance, you want the sign to appear close to the appropriate element to show their association. If you put a + or a − with nothing before it but you want it to be handled like a binary operator you can add an invisible character before the operator using {}. This can be useful if you are writing multiple-line formulas, and a new line could start with a = or a +, for example, then you can fix some strange alignments adding the invisible character where necessary.
A plus-minus sign used for uncertainty is written as:
\[
 \pm
\
]
\pm

Controlling horizontal spacing

LaTeX is obviously pretty good at typesetting maths—it was one of the chief aims of the core Tex system that LaTeX extends. However, it can't always be relied upon to accurately interpret formulas in the way you did. It has to make certain assumptions when there are ambiguous expressions. The result tends to be slightly incorrect horizontal spacing. In these events, the output is still satisfactory, yet any perfectionists will no doubt wish to fine-tune their formulas to ensure spacing is correct. These are generally very subtle adjustments.
There are other occasions where LaTeX has done its job correctly, but you just want to add some space, maybe to add a comment of some kind. For example, in the following equation, it is preferable to ensure there is a decent amount of space between the maths and the text.
\[
  f(n) = \left\{
  \begin{array}{l l}
    n/2 & \quad \text{if $n$ is even}\\
    -(n+1)/2 & \quad \text{if $n$ is odd}\\
  \end{array
} \right.
\
]
f(n) =
\begin{cases}
n/2 & \quad \text{if } n \text{ is even} \\
-(n+1)/2 & \quad \text{if } n \text{ is odd}\\ 
\end{cases}
This code produces errors with Miktex 2.9 and does not yield the results seen on the right. Use \textrm instead of just \text.

(Note that this particular example can be expressed in more elegant code by the cases construct provided by the amsmath package described in Advanced Mathematics chapter.)
LaTeX has defined two commands that can be used anywhere in documents (not just maths) to insert some horizontal space. They are \quad and \qquad
A \quad is a space equal to the current font size. So, if you are using an 11pt font, then the space provided by \quad will also be 11pt (horizontally, of course.) The \qquad gives twice that amount. As you can see from the code from the above example, \quads were used to add some separation between the maths and the text.
OK, so back to the fine tuning as mentioned at the beginning of the document. A good example would be displaying the simple equation for the indefinite integral of y with respect to x:
\int y\, \mathrm{d}x
If you were to try this, you may write:
\[ \int y \mathrm{d}x \] \int y \mathrm{d}x
However, this doesn't give the correct result. LaTeX doesn't respect the white-space left in the code to signify that the y and the dx are independent entities. Instead, it lumps them altogether. A \quad would clearly be overkill is this situation—what is needed are some small spaces to be utilized in this type of instance, and that's what LaTeX provides:
Command Description Size
\, small space 3/18 of a quad
\: medium space 4/18 of a quad
\; large space 5/18 of a quad
\! negative space -3/18 of a quad
NB you can use more than one command in a sequence to achieve a greater space if necessary.
So, to rectify the current problem:
\[ \int y\, \mathrm{d}x \] \int y\, \mathrm{d}x
\[ \int y\: \mathrm{d}x \] \int y\;\;\!\! \mathrm{d}x
\[ \int y\; \mathrm{d}x \] \int y\; \mathrm{d}x
The negative space may seem like an odd thing to use, however, it wouldn't be there if it didn't have some use! Take the following example:
\[
  \left(
    \begin{array}{c}
      n \\
      r
    \end{array}
  \right) = \frac{n!}{r!(n-r)!
}
\
]
\left(
   \begin{matrix}
     n \\
     r
   \end{matrix}
   \right) = \frac{n!}{r!(n-r)!}

The matrix-like expression for representing binomial coefficients is too padded. There is too much space between the brackets and the actual contents within. This can easily be corrected by adding a few negative spaces after the left bracket and before the right bracket.
\[
  \left(\!
    \begin{array}{c}
      n \\
      r
    \end{array}
  \!\right) = \frac{n!}{r!(n-r)!
}
\
]
\left(\!
   \begin{matrix}
     n \\
     r
   \end{matrix}
   \!\right) = \frac{n!}{r!(n-r)!}
In any case, adding some spaces manually should be avoided whenever possible: it makes the source code more complex and it's against the basic principles of a What You See is What You Mean approach. The best thing to do is to define some commands using all the spaces you want and then, when you use your command, you don't have to add any other space. Later, if you change your mind about the length of the horizontal space, you can easily change it modifying only the command you defined before. Let us use an example: you want the d of a dx in an integral to be in roman font and a small space away from the rest. If you want to type an integral like \int x \; \mathrm{d} x, you can define a command like this:
\newcommand{\dd}{\; \mathrm{d}}
in the preamble of your document. We have chosen \dd just because it reminds the "d" it replaces and it is fast to type. Doing so, the code for your integral becomes \int x \dd x. Now, whenever you write an integral, you just have to use the \dd instead of the "d", and all your integrals will have the same style. If you change your mind, you just have to change the definition in the preamble, and all your integrals will be changed accordingly.

Advanced Mathematics: AMS Math package

The AMS (American Mathematical Society) mathematics package is a powerful package that creates a higher layer of abstraction over mathematical LaTeX language; if you use it it will make your life easier. Some commands amsmath introduces will make other plain LaTeX commands obsolete: in order to keep consistency in the final output you'd better use amsmath commands whenever possible. If you do so, you will get an elegant output without worrying about alignment and other details, keeping your source code readable. If you want to use it, you have to add this in the preamble:
\usepackage{amsmath}

Introducing text and dots in formulas

amsmath defines also the \dots command, that is a generalization of the existing \ldots. You can use \dots in both text and math mode and LaTeX will replace it with three dots "…" but it will decide according to the context whether to put it on the bottom (like \ldots) or centered (like \cdots).

Dots

LaTeX gives you several commands to insert dots in your formulas. This can be particularly useful if you have to type big matrices omitting elements. First of all, here are the main dots-related commands LaTeX provides:
Code Output Comment
\dots \dots generic dots, to be used in text (outside formulas as well). It automatically manages whitespaces before and after itself according to the context, it's a higher level command.
\ldots \ldots the output is similar to the previous one, but there is no automatic whitespace management; it works at a lower level.
\cdots \cdots These dots are centered relative to the height of a letter. There is also the binary multiplication operator, \cdot, mentioned below.
\vdots \vdots vertical dots
\ddots \ddots diagonal dots
\iddots
inverse diagonal dots (requires the mathdots package)
\hdotsfor{n} \ldots \ldots to be used in matrices, it creates a row of dots spanning n columns.
Instead of using \ldots and \cdots, you should use the semantically oriented commands. It makes it possible to adapt your document to different conventions on the fly, in case (for example) you have to submit it to a publisher who insists on following house tradition in this respect. The default treatment for the various kinds follows American Mathematical Society conventions.
Code Output Comment
A_1,A_2,\dotsc, LaTeX Dotsc.png for "dots with commas"
A_1+\dotsb+A_N LaTeX Dotsb.png for "dots with binary operators/relations"
A_1 \dotsm A_N LaTeX Dotsm.png for "multiplication dots"
\int_a^b \dotsi LaTeX Dotsi.png for "dots with integrals"
A_1\dotso A_N LaTeX Dotso.png for "other dots" (none of the above)

List of Mathematical Symbols

All the pre-defined mathematical symbols from the \TeX\ package are listed below. More symbols are available from extra packages.
Relation Symbols
Symbol Script Symbol Script Symbol Script Symbol Script Symbol Script
\leq \leq \geq \geq \equiv\, \equiv \models \models \prec \prec
\succ \succ \sim \perp \perp \preceq \preceq \succeq \succeq
\simeq \simeq \mid \mid \ll \ll \gg \gg \asymp \asymp
\parallel \parallel \subset \subset \supset \supset \approx \approx \bowtie \bowtie
\subseteq \subseteq \supseteq \supseteq \cong \cong \sqsubset \sqsubset \sqsupset \sqsupset
\neq\, \neq \smile \smile \sqsubseteq \sqsubseteq \sqsupseteq \sqsupseteq \doteq \doteq
\frown \frown \in \in \ni \ni \notin \notin \propto \propto
\vdash \vdash \dashv \dashv <\, < >\, > =\, =
Greek Letters
Symbol Script
\Alpha\, and \alpha\, \Alpha and \alpha
\Beta\, and \beta\, \Beta and \beta
\Gamma\, and \gamma\, \Gamma and \gamma
\Delta\, and \delta\, \Delta and \delta
\Epsilon\,, \epsilon\, and ε \Epsilon, \epsilon and \varepsilon
\Zeta\, and \zeta\, \Zeta and \zeta
\Eta\, and \eta\, \Eta and \eta
\Theta\,, \theta\, and \vartheta \Theta, \theta and \vartheta
\Iota\, and \iota\, \Iota and \iota
\Kappa\, and \kappa\, \Kappa and \kappa
\Lambda\, and \lambda\, \Lambda and \lambda
\Mu\, and \mu\, \Mu and \mu
\Nu\, and \nu\, \Nu and \nu
\Xi\, and \xi\, \Xi and \xi
\Omicron\, and \omicron\, \Omicron and \omicron
\Pi\,, \pi\, and \varpi \Pi, \pi and \varpi
\Rho\,, \rho\, and \varrho \Rho, \rho and \varrho
\Sigma\,, \sigma\, and \varsigma \Sigma, \sigma and \varsigma
\Tau\, and \tau\, \Tau and \tau
\Upsilon\, and \upsilon\, \Upsilon and \upsilon
\Phi\,, \phi\,, and φ \Phi, \phi and \varphi
\Chi\, and \chi\, \Chi and \chi
\Psi\, and \psi\, \Psi and \psi
\Omega\, and \omega\, \Omega and \omega
Binary Operations
Symbol Script Symbol Script Symbol Script Symbol Script
\pm\, \pm \cap\, \cap \diamond \diamond \oplus \oplus
\mp \mp \cup \cup \bigtriangleup \bigtriangleup \ominus \ominus
\times\, \times \uplus \uplus \bigtriangledown \bigtriangledown \otimes \otimes
\div \div \sqcap \sqcap \triangleleft \triangleleft \oslash \oslash
\ast \ast \sqcup \sqcup \triangleright \triangleright \odot \odot
\star \star \vee \vee \bigcirc \bigcirc \circ \circ
\wedge \wedge \dagger\, \dagger \bullet \bullet \setminus\, \setminus
\ddagger\, \ddagger \cdot \cdot \wr \wr \amalg \amalg
Set and/or Logic Notation
Symbol Script
\exists\, \exists
\nexists\, \nexists
\forall\, \forall
\neg\, \neg
\in\, \in
\notin\, \notin
\ni\, \ni
\land\, \land
\lor\, \lor
\rightarrow\, \rightarrow
\implies\, \implies
\Rightarrow\, \Rightarrow (preferred for implication)
\iff\, \iff
\Leftrightarrow\, \Leftrightarrow (preferred for equivalence (iff))
\top\, \top
\bot\, \bot
\emptyset\, and \varnothing\, \emptyset and \varnothing
Delimiters
Symbol Script
\uparrow\, \uparrow
\Uparrow\, \Uparrow
\downarrow\, \downarrow
\Downarrow\, \Downarrow
\{\, \{
\}\, \}
\lceil\, \lceil
\rceil\, \rceil
\lfloor\, \lfloor
\rfloor\, \rfloor
\langle\, \langle
\rangle\, \rangle
/\, /
\backslash\, \backslash
|\, |
\|\, \|
Other symbols
Symbol Script
\partial \partial
\infty \infty
\nabla \nabla
\hbar \hbar
\Box \Box
\aleph \aleph
\ell \ell
\imath \imath
\jmath \jmath
\Re \Re
\Im \Im
\wp \wp
\eth \eth

Trigonometric Functions
Symbol Script Symbol Script Symbol Script Symbol Script
sin  \sin cos  \cos tan  \tan cot  \cot
arcsin  \arcsin arccos  \arccos arctan  \arctan arccot  \arccot
sinh  \sinh cosh  \cosh tanh  \tanh coth  \coth
sec  \sec csc  \csc






 










 Document Link
http://www.eng.cam.ac.uk/help/tpl/textprocessing/
http://www.raphaelbahati.com/docs/raphael-LaTeX.pdf
http://www.cs.washington.edu/orgs/student-affairs/gsc/tutorials/0708/files/latex/latex-intro.pdf
http://www.latex-project.org/guides/
http://www.tex.ac.uk/tex-archive/info/beginlatex/html/

command
http://www.stdout.org/~winston/latex/latexsheet.pdf
http://amath.colorado.edu/documentation/LaTeX/Symbols.pdf
http://www.iitg.ernet.in/sbdas/LaTeX_Symbol.pdf
http://www.rpi.edu/dept/arc/training/latex/LaTeX_symbols.pdf
http://ekalavya.imsc.res.in/tex-archive/info/symbols/comprehensive/symbols-a4.pdf
http://www.math.toronto.edu/mathit/symbols-letter.pdf

table
http://www.maths.leeds.ac.uk/latex/TableHelp1.pdf
http://nepsweb.co.uk/docs/tableTricks.pdf
http://www.tug.org/TUGboat/tb28-3/tb90hoeppner.pdf

example

http://pangea.stanford.edu/computing/unix/formatting/latexexample.php



http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/GSWLaTeX.pdf
http://ece.uprm.edu/~caceros/latex/introduction.pdf
http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/
http://www.eng.cam.ac.uk/help/tpl/textprocessing/ltxprimer-1.0.pdf
http://www.cs.cornell.edu/info/misc/latex-tutorial/latex-home.html
http://www.pages.drexel.edu/~pyo22/students/latexRelated/latexTutorial.html
http://tug.org/tutorials/tugindia/
http://tobi.oetiker.ch/lshort/lshort.pdf
http://www.duke.edu/~hpgavin/tutorial.pdf