# class5 - PHYS 5900 Class 5(Fri Zi-Wei Lin In[1:= Out[1]=...

This preview shows pages 1–5. Sign up to view the full content.

PHYS 5900 Class 5 (9/04/2009Fri) Zi-Wei Lin In[1]:= NIntegrate @ Exp @ x^2 ê 2 Sqrt @ 2 Pi D , 8 x, 2, 2 <D Out[1]= 0.9545

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Fortran program of the integral Ÿ - 2 2 e x 2 ë 2 dx í 2 π is available at http://siyu.physics.ecu.edu/zlin/Fortran/ as integral.f, download it to your Mac computer, open Terminal, then type the following command mv ~/Desktop/integral.f . ls to move it to the current directory. Note: there are 2 spaces in the above command. 1 ) The trapezoidal rule: X 0 X n f H x L Å x i = 0 n 1 B f H X i L + f H X i + 1 L 2 F H X i + 1 X i L = d i = 1 n 1 f H X i L + d 2 @ f H X 0 L + f H X n LD , if H X i + 1 X i L = d . 2 L The Simpson rule : if n is even and H X i + 1 X i L = d X 0 X n f H x L Å x d 3 @ f H X 0 L + 4f H X 1 L + 2f H X 2 L + 4f H X 3 L + ... + 2f H X n 2 L + 4f H X n 1 L + f H X n LD 2 class5-f.nb
Some basics of Fortran programming: The parameter statement: must appear before the first executable statement; parameter (pi=3.1415926) assigns a constant value to the variable pi . If statements: if (logical expression) then statements elseif (logical expression) then statements : else statements endif Note: elseif and/or else components above are optional. You can also use if (logical expression) statement mod (n,d) gives the remainder when n is divided by d; e.g. mod(nx,2)=1 means nx is odd. Logical operators: .eq. (meaning =) .ne. (meaning π ) .gt. (meaning >) .ge. (meaning ) .lt. (meaning <) .le. (meaning £ ) .and. .or. (meaning ||) .not. (meaning !) OPEN(unit#, file='filename') can be used to connect a file to a unit#; class5-f.nb 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
WRITE(unit#, format) list write list to a file associated with unit# using a format; unit# =6 or * represents the standard output; format =* means unformatted,
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/25/2010 for the course PHYS 5900 taught by Professor Lin during the Fall '09 term at East Carolina University .

### Page1 / 11

class5 - PHYS 5900 Class 5(Fri Zi-Wei Lin In[1:= Out[1]=...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online