Introduction 2

Topics to cover:

Data manipulation. List and Arrays. Solving Matrix Equations. Curve fitting by least squares method. Numerical Extrapolation.

Refer to Chapter 3, DeVries for certain parts of the topics discussed.

data={{0,-1.1},{1,2.1},{2,3.1},{3,3.98},{4,5.2},{6,7.22}};
lpdata=ListPlot[data,Joined->False,Mesh->All];
fitdata=Fit[data, {1,x},x]
a=fitdata[[1]];
b=fitdata[[2]];
const=0.023142857142859113;slope=1.27257;
y[x_]:=const + slope*x;
py=Plot[y[x],{x,0,6}];
Show[lpdata,py]

y[3.5]

NSolve[y[x]==0,x]

Data manipulation: Creating data files and how to post-process them.

Exercise: Write a loop to generate say 10 data files, named 1.dat, 2.dat, ...,10.dat. Each *.dat file should contain a randomly generated ‘0’ or ‘1’. Then write another independent program to scan through the *.dat files in the directory. Read in these *.dat sequentially, begining from 1.dat, then 2.dat, ...,10.dat. Identify which of the *.dat is the first one that contains a ‘1’.

The purpose of the above exercise is to give you an idea how to export your numerical results into properly sequenced *.dat files, and how to postprocess them using simple programming instructions. Many data manipulation in actual situations involved the similar procedures as the above exercise.

Assignment: Write a loop to generate say 10 data files, named 1.dat, 2.dat, ...,10.dat. Each *.dat file should contain a randomly generated ‘0’ or ‘1’. Then write another independent program that determines which *.dat files are the 6-th one (starting from 0.dat.) that contains a ‘0’. You program should be smart enough to warn you if there is no such *.dat file exist.

Visualation of xyz data: Download the zipped file at http://www2.fizik.usm.my/tlyoon/teaching/ZCE111/1213SEM1/notes/Introduction/xyzdata/xyzdata.zip
Unzip it. Use mathematica to import the file named “1.dat”. This data file contains the positions of many particles at the timestep t =1, hence the name of the data file “1.dat”. Similarly, data n.dat contains the positions of all the atoms at timestep n. 

Q1: How many atoms are there in the data file?
Q2. Visualise the 3D configuration of these atoms using mathematica. The command to use: ListPointPlot3D[dat1, BoxRatios -> {1, 1, 1}]ListPointPlot3D[dat1, BoxRatios -> {1, 1, 1}].
Q3. Import the files in numerical order and display them one by one in a sequence. 
Q4. Do this using Manipulate.

Download the file bdsimplified.dat from http://www2.fizik.usm.my/tlyoon/teaching/ZCE111/1213SEM1/notes/Introduction/xyzdata/.This is a structured data file with a format. The first colume is the index assigned to an atom, column 2 is the type of atom, and column 3 is the biding energy of that atoms. For example, in the second row of bdsimplified.dat,

2 3 -5.76691 

means the atoms is identified as atom with index 2, of type 3, and its binding energy is -5.76691. Write a program to calculate the average biding energy for atom type 3.

Download the file bd1.dat from http://www2.fizik.usm.my/tlyoon/teaching/ZCE111/1213SEM1/notes/Introduction/xyzdata/.This is a structured data file with a slightly more complicated format. It keeps the record of the binding energy of the atoms at all time step. Write a program to that plots the average binding energy of atom type 3 as a function of time step.

Homework assignment: Download http://www2.fizik.usm.my/tlyoon/teaching/ZCE111/1213SEM1/notes/Introduction/xyzdata/bd2.dat. .This is a structured data file with a slightly more complicated format. It keeps the record of the binding energy of the atoms at all time step. Write a program to that plots the average binding energy of atom type 1 as a function of time step. Modify your program to plot the average binding energy of atom type 2 as a function of time step. Note that the biding energy for atom type 1 is in column 3, while  the biding energy for atom type 2 is in column 4.

List and Arrays: Some exercises.

Solving Matrix Equations using Mathematica.