Introduction to Computing Basics
Introduction to Computing Basics
Karin Carling
Göteborg 2001
Contents
1 Basic Unix 1
1.1 First meeting with the computer . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Simple file-system exercise . . . . . . . . . . . . . . . . . . . 2
1.2 Basic Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Make a file . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 More exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 How to use the manual . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Redirect and pipelining . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.6 File quota . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.7 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.7.1 Lock your account! . . . . . . . . . . . . . . . . . . . . . . . 4
1.7.2 Change password! . . . . . . . . . . . . . . . . . . . . . . . 4
1.8 Finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.9 Log off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.10 How to learn more . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Introduction to LATEX 7
2.1 Getting started with LATEX . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 Typing text . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.2 Typing math . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.3 Graphics and tables . . . . . . . . . . . . . . . . . . . . . . . 11
2.1.4 References and bibliography . . . . . . . . . . . . . . . . . . 12
2.2 How to learn more about LATEX . . . . . . . . . . . . . . . . . . . . . 12
i
ii CONTENTS
Basic Unix
First you will learn some basic commands for the Unix-system, the basics about the
file-system, and how to make text-files with the editor Emacs. This knowledge is es-
sential if you are going to use the computers at Djungeldata.
1.1.1 Commands
1. Write some simple commands, e.g. date, cal and who.
2. Misspell on purpose and correct it. You can move back and forth on the com-
mand line with the arrow-keys, and , and remove characters in front of
the marker with Backspace. It is the key above the return-key with an arrow
pointing to the left. You can also use Control-d (the Control-key is held down
simultaneously with the d-key, short: C-d) if you want to remove the character
which the marker covers.
Tab-expansion is also good to know. The command interpreter may fill-in your
commands and file names. Write xre and press the Tab-key, and you will get
xrefresh. This will work if there is an unique choice to make. If you write
ma and try tabular-expansion, you will get a beep as the answer. Now write C-d
and you will get a list of the commands beginning with ma.
3. Give the command man for some program, e.g. who. (New page = space,
end listing = q).
4. Go through your previously executed commands with the arrow-keys and .
Try the command history.
1
2 CHAPTER 1. BASIC UNIX
1. Find out on which day of the week you are born with cal.
3. Count the number of characters, words and lines in the file indata with wc.
boromir ls
file1 newfile other.file my.file
boromir ls > listres
boromir
Commands that normally read their input from the terminal can be made to read this
data from a file with <. If we would like to count the number of words, i.e. the number
of files in the present directory, in the file listres we created above we can do the
following.
It is not necessary to make a file every time you would like to count the number of
files in a directory, you can connect the commands with a pipe ( ). This will cause the
output from the first command to be piped to the other command.
boromir ls wc -w
The redirects shown above is only the basic ones. If you are curious of more in-
formation about this read the manual pages of the command shell, i.e. man csh.
And finally a little exercise (write the commands you use):
1. Sort the file indata in the inverse alphabetical order and save the result in the
file atadni with a redirect.
4 CHAPTER 1. BASIC UNIX
This output shows that you use 5 kb disk-space of the allowed usage of 50000 kb, that is
50 Mb, and during a short period of time you may use up to 75 Mb of disk-space. You
have 6 files stored and there are no limits to the number of files that you are allowed to
have on the file-system.
How much disk-space are you using? If you get a message that you have used more
disk-space than your quota allows you should clean up immediately on you account,
that is delete files.
1.7 Security
The world is full of wicked people who enjoy to steal or destroy other peoples work,
including yours, and they are at Chalmers too, actually. Therefore, it is of uttermost
importance that you make everything in your power to prevent unauthorized access to
your account.
1.8 Finally
The command-list, see appendix A.1 contains a lot of useful commands and programs.
The following commands are very useful, I suggest that you learn them by heart: cat,
cd, cp, emacs, grep, kill, lpq, lpr, lprm, ls, man, mkdir, more, mv, nispasswd, pine, ps,
printerquota, pwd, quota, rm, rmdir, top, wc, xlock.
1.9. LOG OFF 5
Introduction to LATEX
There are a lot of programs for writing reports and other documents. Some of them
are similar to Word, e.g. StarOffice, some are more enhanced, e.g. FrameMaker, and
then there is LATEX. This part will teach you the basics of LATEX since it is a powerful
typesetting program which can be found, or installed for free, on almost any computer
system. To be able to use LATEX, you also need to know how to use a text editor, e.g.
Emacs.
\begin{document}
...
\end{document}
which marks the enclosed text as the part of the document that is to be typeset according
to the “rules” of the preamble, and the mark-up commands in the text of the body.
In the body you have the abstract, the main text which is divided into sections, and
in the end a list of literature references, the bibliography.
To get a typset document from the source file (ltest.tex) you will have to run
the following commands:
latex ltest
xdvi ltest.dvi &
7
8 CHAPTER 2. INTRODUCTION TO LATEX
\documentclass[...]{...}
\usepackage{...} preamble
\begin{document}
\title{...}
\author{...} top matter
\date{...}
\maketitle
\begin{abstract}
... abstract
\end{abstract}
body
\section{...}
\section{...}
\begin{thebibliography}{...}
\bibitem{...}... bibliography
\end{thebibliography}
\end{document}
Figure 2.1: The basic structure of a source file
The formatted document will appear in a new window on the screen. If you want to
print the document you have to apply one more command to the file:
dvips ltest.dvi
This will generate a file ltest.ps which can be viewed (ghostview) or printed
(lpr).
, ; . ? ! : ‘ ’ -
and the space-bar, the tab key (which gives the same effect as the space-bar in the
typeset document), and the Return key. There are also thirteen keys that are mostly
used in LATEX instructions:
# $ % & ˜ _ ˆ \ { } @ " |
If you want to typset these caracters there are commands available, see App. A.3.3.
The other (swedish) keys on your keyboard cannot be used, unless you include a
package that can handle this input. At Djungeldata your can include the inputenc
package.
To give you an idea of how the source file might look like, here is a short example
of how to write some text in LATEX:
\documentclass[a4paper, 12pt]{article}
% This is a comment which will be ignored.
\begin{document}
\section{First section}
\label{thefirst}
Here you can write the text you like. The number of
spaces between the words will be ignored when the
text is typset
as well as
any single linebreaks.
\end{document}
The source file begins with
\documentclass[a4paper, 12pt]{article}
which specifies the class of the document (article) and includes the optional argu-
ments a4paper and 12pt which states that this document should be typset for the
paper size a4 and with the font size 12 points.
The second line is a comment. When LATEX encounters the %-character the rest of
the line in the source file will be ignored. This can be conveinient if you want to add
some notes to your source file.
The text of the document is typed within the document environment. An envir-
onment is the region between any pair of
\begin{...} \end{...}
where the enviroment type is given within the braces.
The text is sectioned with the section command which can be accompanied by
a label command that ties a short name to the section heading to make it easy to
refer to this section later in the document, see Section 2.1.4. There are several levels of
sectioning available. The number of levels depend on the class of the document.
10 CHAPTER 2. INTRODUCTION TO LATEX
As can be seen from the typeset document, LATEX notices that there is a space or tab
in the file but it ignores how many, and puts only one space in the typset document. The
same is true for blank lines, which will cause LATEX to make a new paragraph. Usually
the spacings will be typeset correctly, but once in a while you might run in to trouble.
You might want a space between two words but you do not want a linebreak between
the words. Then you can “tie” the words together with the ˜(tilde), which will give a
nonbreakable space.
Another problem you might encouter is that the hyphenation is incorrect. Usually,
english words will be hyphenated correctly, but there might be names of technical terms
that are difficult to handle. To help with the hyphenation, you can insert one or more
optional hyphen commands ( -) to show LATEX where the word might be hyphenated.
If the word occurs many times in the document, you can use a “global solution”, by
putting the word with optional hyphens in the preamble instruction
\hyphenation{in\-struction}
The inline environment open and close with $, and the displayed environment is
contained within
\begin{equation}
...
\end{equation}
The equation environment includes the possibility to label the equation for easy
cross-referencing, see Section 2.1.4, with the label , name - command, and the
equation will be numbered.
There are many commands within the math environments to give the components
of an equation. LATEX includes almost any mathematical symbol you might like to use,
and there are a number of packages that give you access to even more symbols. A list
of the most common components is found in App. A.3.4.
\includegraphics
\scalebox
\rotatebox
which might come in handy when you are importing your graphics.
The graphics you like to import are placed within the figure environment. Below
is an example of the command series used to put a centered figure (my-fig.eps) into
a document.
\begin{figure}[htbp]
\begin{center}
\includegraphics{my-fig}
\caption{The caption of the figure is written here.}
\label{fig:myfigure}
\end{center}
\end{figure}
The includegraphics command assumes that the file suffix is .eps. If there is
no such file it looks for a file with suffix .ps. The figure can be labelled for easy
cross-referencing, and you can include a figure caption with explanatory text.
Sometimes your data is better shown as a table. In LATEX you will construct a table
with the tabular and table environments. The following text in the source will
produce the table as shown below.
\begin{table}[h]
\begin{center}
\begin{tabular}{| l | l | r|}
\hline
12 CHAPTER 2. INTRODUCTION TO LATEX
First Steps in LATEX G. Grätzer. If you read and do the exercises of this book you
have achieved the skills you need to make an article. Quite short.
This part will get you started with MATLAB and give you the basic knowledge for
using the program. If you are going to pass the Computational Physics course in the
spring it is important that you continue to practice and improve on your MATLAB
skills.
x=14
y=3*x
The usual mathematical functions are available within MATLAB, e.g. sin. Par-
entheses are used as usual. If you put a semicolon at the end of a command the com-
putation will be performed as usual but there will be no output on the screen. This is
convenient when you are working with large arrays of data.
15
16 CHAPTER 3. COMPUTING AND PROGRAMMING WITH MATLAB
If you are curious of the variables saved by MATLAB, check them with the com-
mands who and whos. The last command will give more details about the variables
stored. To clear all variables you type clear, which can be used to clear one variable
at the time too. (How do you do that?)
Variables in MATLAB are vectors and matrices. Enter this and comment on the
output.
vcol=[1;2;3;4], vrow=[1 2 3 4]
A=[1 2 3 4;5 6 7 8;9 10 11 12]
sqrt(vcol),sqrt(A)
If you need a long vector you do not want to enter every number by hand. The
colon-operator is a tool for the construction of vectors:
vector=0:8
vector2=0:0.5:2
values=2.ˆvector
If you have defined some variables you can use those to create new variables.
table=[vector;vector.ˆ2;vector.ˆ3]
plot(vector,values)
To get a smoother curve you use more values. Try to make a smooth plot of the
powers of 2. Read the help-file and learn how to get different colors and line-types in
your graph.
It is also possible to do 3D-graphics.
vector2=0:0.5:8;
[X,Y]=meshgrid(vector2);
mesh(X,Y,2.ˆX+2.ˆY);
random=rand(1,7)
hist(random);
3.3. SYSTEMS OF LINEAR EQUATIONS AND EIGENVALUES 17
or use the menus of the figure window. This will give you a file filename.eps in
the working directory. This file can be imported into your document. (If you want to
learn more about the flags given to the print-command try the MATLAB-helpdesk.)
Enter them into MATLAB. You can multiply the matrices with B*A. What happens if
you type A*B? Why? Try some other matrix commands on these matrices, e.g. det,
trace, null, orth and inv. Try to understand what these commands do.
To solve a system of linear equations e.g.
I 6 3 ; 3 . >.
JK #ML #ON #QPR8
. 3 > 3 > 17S
#ML #ON #QPR8 (3.2)
3 > 3 6 176
#ML #ON #QPR8
b=[25;18;13];
x=A\b
function y = div(n,d)
To avoid problems, do not give your functions the same name as a built-in MATLAB
function, and give the source file the same name as the function, e.g. div.m for the
function div.
On the home page of the course there is a program available for you to read and
run. Try to understand every command in this program and what they do before you
run to see the result.
Try to make some MATLAB programs on you own. You might have some prob-
lems from one of the other courses you are taking that you might try and solve with
MATLAB.
This document contains some lists with the most common commands used on the Djun-
geldata computer system, and in some of the programs that you will use during your
education at the Physics Department. It is a good idea to check that you are famil-
iar with these commands. If not, learn more about them through the manual and help
pages.
man command Show the manual page for the command. I strongly suggest that you
learn how to use this command and how to read the manual pages.
apropos keyword Locate commands by keyword lookup.
nispasswd Use this to change your password.
xlock Lock the workstation for a short period of time.
pwd Print the path to the present working directory, i.e. the directory in which you
currently are positioned.
ls List the files and directories in the current directory. Some optional flags:
-l Long listing, gives information about size, owner, date, and status of files and
directories.
-a Show all files and directories, including the hidden ones (.name).
-F Shows markers at the file and directory names, e.g. a directory is marked
with a trailing slash(/).
mkdir name Create a new directory called name in the current directory
rmdir name Remove the directory called name. (This requires that the directory is
empty.)
19
20 APPENDIX A. SHORT GUIDE TO BASIC COMMANDS
cd name Change directory. If no directory name is give you will end up in your home
directory.
chmod flags file Change the status (mode) of the file or directory. Use this to protect
you files. Some flags:
u+x Gives the user (you) the right to execute the file.
og-rwx Removes all rights for other users to read, write or execute your file
(directory).
ps List the process numbers of the processes that are running on the computer.
top Allows you to check the load of the computer. Can be used to identify and kill a
looping process.
kill pid This command kills the process which you tell it to kill. Be careful when using
this.
quota -v Show how much of your quota of disk-space that you are using.
printerquota Show how many pages you can print from your account. If you need
more pages you can by extra printer quota from F-styret.
lprm jobid Remove your printer job from the printer queue.
more file Show file contents on the screen one page at the time.
wc file Count the number of lines, words and characters in the file.
sort flags file Sort the contents of the file (the flags are optional). You can sort in a lot
of ways if you learn how to use the flags.
A.2 Emacs
This is a short list of key bindings that is useful when you are working with emacs. If
there is a dash (-) you should hold these keys down at the same time, and key bindings
should be done in sequence. The C-x is short for holding down the Control-key and x-
key at the same time, and M-x is the Meta-key and the x-key at the same time. Usually,
the Meta-key is a rhombi-marked key.
C-x C-f Find file, i.e. read a file into emacs for editing.
C-x i Insert file into the active buffer.
C-x C-s Save buffer to file.
C-x C-w Save buffer to a new file-name and make that file the active buffer.
C-x b Change to another buffer.
C-x u or C- Undo the previous change, can be repeated.
C-f One character forward.
C-b One character backward.
C-p Go upward one line.
C-n Go down one line.
M-f Move one word forward.
M-b Move one word backward.
C-a Move to the beginning of the line.
C-e Move to the end of the line.
M- U Move to the beginning of the document.
M- Move to the end of the document.
M-x goto-line Go to line n in the buffer. You will get a prompt asking for the line
number.
C-v Page down.
M-v Page up.
C-Space Put the mark here, the current position.
C-k Cut from the marker to the end of line. Repeat for several rows.
C-w Cut the area from the mark to the current position of the marker.
M-w Copy the area from the mark to the current position of the marker.
C-y Paste the latest cut/copy. Can be used repeatedly.
C-s Search forward.
C-r Search backward.
M-x doctor If you find Emacs frustrating.
M-x hanoi If you are bored...
22 APPENDIX A. SHORT GUIDE TO BASIC COMMANDS
A.3 LATEX
Here are some of the most common tags that are used when you write a document
in LATEX. Every tag begins with a and the environments have a begin , env - at the
beginning and a end , env - at the end.
A.3.1 Environments
document This is the environment in which the document is set. Everything that is
written before this environment begins is called the pre-amble.
equation Will put you in math-mode and allow you to type an equation that you can
for reference. The equation will be numbered.
table You can typeset tables within this environment. Mostly used together with the
tabular.
cite Reference a book, article or other bibliographic item from the reference list.
includegraphics Used when you want to import a picture, ps or eps formatted, into the
document. (You will need to include the graphics-package in the pre-amble.)
footnote Create a footnote at the bottom of the page containing the text included in
the command.
A.3. LATEX 23
There are a lot of other tags and environments available. Read the dd-LATEX home
pages and take a look at the commands at
http://mitra.phys.uit.no/edb/latex/index.html,
or buy the book “LATEX – user’s guide and reference manual” by L. Lamport.
24 APPENDIX A. SHORT GUIDE TO BASIC COMMANDS
A.4 MATLAB
This is a short list of useful command in MATLAB. Consult the MATLAB-help to
learn more about how to use them.
quit Quit the MATLAB session. Remember to always quit MATLAB before you log
out!
help On-line help, display text at command line.
helpwin On-line help, separate window for navigation.
helpdesk Comprehensive hypertext documentation and troubleshooting. Helpdesk
loads the main MATLAB Help Desk page into the Web browser.
lookfor Search MATLAB for functions that matches some keyword.
format Set the output format.
more Control paged output in command window.
ones Gives you an array of only ones.
zeros Gives you an array of only zeros.
eye Gives you the identity matrix.
rand Gives you an array of uniformly distributed random numbers.
size Gives the dimensions of an array.
length Gives the size of the largest dimension of the array.
eps Floating point relative accuracy. This is the highest accuracy you can get out of
MATLAB.
abs Get the absolute values of the elements in an array.
/ Right matrix divide.
./ Right array divide, elementwise.
* Matrix multiply.
.* Elementwise array multiply.
eig Get the eigenvalues and eigenvectors of a matrix.
diag If you give a vector as the argument you will get a diagonal matrix with that
vector as the diagonal, if you give a matrix as the argument you will get the
diagonal of that matrix as a vector.
sum Returns the sum of the elements in an array.
fft One-dimensional discrete Fourier transform.
ifft One-dimensional inverse discrete Fourier transform.
fftshift Shift DC component to center of spectrum.
A.4. MATLAB 25
ode45 Solve non-stiff differential equations, medium order method. MATLAB also
provides some other methods of solving differential equations.