Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computational physics PY2050 Course Details:

Similar presentations


Presentation on theme: "Computational physics PY2050 Course Details:"— Presentation transcript:

1 Computational physics PY2050 Course Details: http://www.tcd.ie/Physics/People/Charles.Patterson/teaching/PY2050_CP

2 Why computational physics? Experimental data will often require some degree of signal processing. Time dependent data Fourier transform Frequency dependent data Finding the disordered atomic structure from diffraction data - Reverse Monti Carlo For both for experiment and theory work things are never really as easy in reality as the examples seen in lectures! Here are some examples:

3 Even if we can write down an expression that describes a system we can not alway solve the expressions analytically. For example: The set of differential equations used to describe the weather. Quantum mechanics for more than two particles. Why computational physics?

4 Course general information 6 Weeks course Week 1 - Introduction to Linux and C programming Week 2 to 4 - Finding minima of functions Week 5 and 6 - The non-linear pendulum Lab reports are due in one week after you have completed the lab. Collect information as you it do the lab. Name files so you know what they are. Reports should be in the style of a scientific document. Try to convey all the information in about 4-6 pages. You should describe the algorithms used, however do not include the code.

5 Throughout the lab we will use the Linux operating system The job of the of an operating system is to control the various parts of the computer, such as the cpu, memory, hard drives... and provide a user interface. Example OS: Windows, OSX, Linux, UNIX..

6 How is Linux different to windows and why use it? Open source – Developers are free to edit and develop the OS Many flavours of Linux Red Hat, SuSE, Ubunto... There are no Linux viruses (as of yet) so no need to run a virus checker Generally Linux requires less CPU power and memory than windows Linux is designed to be customized, software development tools come as standard e.g. compilers

7 Equivalent software MS office - Open office (Linux windows and Mac versions available) Internet explorer - Firefox, Mozzila, Netscape, Chrome... Photoshop - gimp MS Outlook - Thunderbird, kmail... Windows media player – mplayer, xmms....

8 Dual boot computers Almost any computer can run Linux It is often advantageous to have both Linux and another OS on the same computer LinuxMBRWindows/OSX

9 Running Linux without installing? Many distribution provide “Live CD's” including Knoppix Ubuntu and open SuSE. http://www.knoppix.org/ http://software.opensuse.org/ http://www.ubuntu.com/getubuntu/download http://puppylinux.org/ Live CD's run the OS from the CD and nothing is installed on your hard disk. This is very useful if you want to continue your lab work at home!

10 Command line Most Linux operations can be done via command line or the graphical interface. Often flashy graphics slow down or complicate simple operations. With software development it is often necessary to use the command line.

11 Command line commands ls list files in the current directory pwd what directory am I in cd change directory cd.. move up a directory cp copy a file cp -r recursive copy so you can copy a directory mkdir make directory rmdir remove directory rm remove file (Note on the command line there is no recycle bin!)‏ rm -rf remove file or directory touch make an empty file man read the manual page for a command

12 File system

13 Getting used to the command line: Open a terminal Find out where you are in the file system Make a directory “myfiles” Make an empty file “file” Move the file into the directory “myfiles” Go into the directory “myfiles” and check that your file is there Remove the directory “myfiles”

14

15 Text editors There are many text editors in linux: gedit, jedit, nedit, emacs, vi, pico, nano, kate.... It doesn't matter which one you use, but some are easier than others try gedit and avoid vi and emacs File extensions – windows knows what program a file belongs to from its file extensions e.g. “sheet.xls” windows will know this is an excel file. Linux does not care what a file is called. Programs written in C are text files until compiled

16 Other useful commands ksnapshot - takes a screen grab which can be incorporated into lab reports oowriter – Similar to MS word, part of OpenOffice gedit – text editor with syntax highlighting for C gnuplot – graph plotting tool ls - list directory content pwd - what directory am I in cp - copy mv - move (also acts as rename)‏ rm – remove (remember there is no recycle bin!)‏

17 Introduction to C programming

18 Where to get extra information free c books http://publications.gbdirect.co.uk/c_book/ http://www.oualline.com/style/

19 Compilers Programs are simply text files (referred to as source code) file extension is usually.c e.g. myprog.c To convert to machine code so that the computer can run it the program needs to be compiled gcc -o myprog myprog.c here we input text file myprog.c, and the output file is called myprog

20 Linking Once all the pieces of code are compiled the code is then gathered together (linked) into an executable. Linking allows functions that have already been written to be included into your executable. A set of pre built functions is called a library e.g. C comes with a maths library which contains functions like sin, cos, asin, tan, log, log10, ceil, floor.... We can build in the standard maths library as follows: gcc -o myprog myprog.c -lm

21 Compile and link

22 Simple program End of line not a full stop

23 Closer look at the simple program The program always starts with the function main. Other functions may also be included but main is the first one to be run. The function printf is contained in the library stdio.h

24 Comments Comments are ignored by the compiler, you should use comments to make notes as to what each section of the code does.

25 Introducing data types and maths library The cos function is part of the library math.h The linker needs to be told where the library math.h can be found. Every variable must fist be assigned so that the correct amount of memory is allocated.

26 Variable types data size depends on implementation but these are typical values

27 Input and output %c - characters %d - integers %f – floats %lf – Long float %s – a string \n – new line Print to screen: printf(“%s %d %f \n”, “red”, 123, 0.02648); Read in: printf(“What is your age: “); scanf(“%d ”,&d);

28 Functions As well as using pre built functions you may write your own function “func” returns the value of sin^2(x)+cos^2(x)‏ You must declare your functions, with the variables sizes they are going to use

29 Control of flow with logical expressions General form: if( condition 1 )‏ statement1; else if( condition 2 )‏ statement2; else if( condition 3 )‏ statement3; else statement4;

30 Control of flow with while statement General form: while(expression)‏ statement

31 For loop syntax: for(initialization; condition for finishing; step)‏ statement

32 C Lab 3 & 4 Finding the minima of functions

33 Why we are interested: Many problems in physics are solved by minimizing or maximizing functions. The lab is divided into 3 sections: Root finding Newton-Raphson method Steepest descents

34 1.2 root finding We do not know the form of the function We have a way of calculating f(x) given x We need to find where f(x)=0 xf(x)‏

35 Start X1= X2= X3=1/2(X1+X2)‏ Find f(X1), f(X2) and f(X3)‏ is f(X3) small Yes X2=X3 Stop is f(X3)< 0 X1=X3 NoNo Yes Algorithm for the roots.c program

36 Using gnuplot A short guide to using gnuplot can be found here: http://www.duke.edu/~hpgavin/gnuplot.html

37 gnuplot - plotting a function

38 Labels and axis

39 2 curves

40 Plotting iterations vs tolerance

41 gnuplot - plotting a data set

42 Try adding a print statement to the program roots.c to print the progress of the program in the loop where the root is found

43 1.4 The Newton-Raphson method What is it for: To minimize the function If we do not know the form of the function If we have a way of calculating f(x) and f'(x) given x xf(x) f '(x)‏

44

45 Ex2 Q2 Finding Na Cl distance

46 Steepest descents For this section it is useful to plot 3d functions

47 C Lab 5 & 6 The nonlinear pendulum

48 Numerical error


Download ppt "Computational physics PY2050 Course Details:"

Similar presentations


Ads by Google