Computational physics PY2050 Course Details:

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Linux, it's not Windows A short introduction to the sub-department's computer systems Gareth Thomas.
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Computational physics PY2050 Course Details:
Getting Started with Linux Douglas Thain University of Wisconsin, Computer Sciences Condor Project October 2000.
16/13/2015 3:30 AM6/13/2015 3:30 AM6/13/2015 3:30 AMIntroduction to Software Development What is a computer? A computer system contains: Central Processing.
Linux+ Guide to Linux Certification, Second Edition
Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Computational physics PY2050 Course Details:
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Unix Basics Chapter 4.
2INC0 Operating Systems Introduction to Linux
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 N305 C Programming. 2 Objectives for the Lab ä Learn problem solving strategies ä Achieve intermediate knowledge of C Programming Language ä Gain experience.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
ENEE150 – 0202 ANDREW GOFFIN Introduction to ENEE150.
Operating Systems and Using Linux CMSC 104, Lecture 3 John Y. Park 1.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Reading None.
Introduction to Programming Using C An Introduction to Operating Systems.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Dr. Sajib Datta Jan 16,  The website is up.  Course lectures will be uploaded there ◦ Check regularly for assignments and update.
General Computer Science for Engineers CISC 106 Lecture 03 James Atlas Computer and Information Sciences 6/15/2009.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
UNIX  Portable (common to many computer architectures), multitasking, multi-user operating system  Introduced by Bell labs in mid-1960’s  Thus, much.
Chapter 1: Introduction to Computers and Programming
Class Projects and Environment
Development Environment
CS1010: Intro Workshop.
Tutorial Six Recap & Linux Basics CompSci Semester Two 2016.
Prepared by: Eng. Maryam Adel Abdel-Hady
UNIX The Basics Source:
The Linux Operating System
Editor, Compiler, Linker, Debugger, Makefiles
Introduction to C Topics Compilation Using the gcc Compiler
Operating Systems and Using Linux
Operating Systems and Using Linux
C Programming Lecture Series
IPC144 Introduction to Programming Using C Week 2 – Lesson 1
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Science I CSC 135.
Operating Systems and Using Linux
Introduction to Linux Week 0 - Thursday.
Topics Introduction to File Input and Output
Operating Systems Lecture 5.
Creating your first C program
Operating Systems and Using Linux
Programming Fundamentals Lecture #3 Overview of Computer Programming
Operating Systems and Using Linux
Operating Systems and Using Linux
Stata Basic Course Lab 2.
Operating Systems and Using Linux
Computational Physics F33SC2
Module 6 Working with Files and Directories
Video Notes.
An Overview of C.
Topics Introduction to File Input and Output
Presentation transcript:

Computational physics PY2050 Course Details:

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:

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?

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.

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..

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

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....

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

Running Linux without installing? Many distribution provide “Live CD's” including Knoppix Ubuntu and open SuSE 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!

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.

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

File system

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”

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

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!)‏

Introduction to C programming

Where to get extra information free c books

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

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

Compile and link

Simple program End of line not a full stop

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

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

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.

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

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, ); Read in: printf(“What is your age: “); scanf(“%d ”,&d);

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

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

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

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

C Lab 3 & 4 Finding the minima of functions

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

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)‏

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

Using gnuplot A short guide to using gnuplot can be found here:

gnuplot - plotting a function

Labels and axis

2 curves

Plotting iterations vs tolerance

gnuplot - plotting a data set

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

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)‏

Ex2 Q2 Finding Na Cl distance

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

C Lab 5 & 6 The nonlinear pendulum

Numerical error