physics for scientists and engineers iii computational ...rfm/phy112lab/112labmanuals_cl2.pdf ·...

3
Illinois State University Physics 112 Department of Physics Physics for Scientists and Engineers III Computational Physics Laboratory 2 Introduction to the FORTRAN Compiler Introduction The first unit introduced the Unix operating system, the BASH shell and simple shell commands, ssh and other networking commands, and the use of text editors. These are essential tools for using any Unix-based computer, including meitner, an Intel quad-core cpu. Two additional tools are required to use the computer effectively for learning and doing physics: a high-level programming language and a graphics package. The programming language used in this course is Fortran 95, a widely used high level programming languages in the sciences and engineering. For visualizing your results, you will use the KaleidaGraph data analysis and graphics software (note: you can also use GNUplot, an open source graphics program, if you prefer). With a familiarity with KaleidaGraph, you should be able to adapt to other packages you may come across in the future. Purpose In this project, you will be introduced to the following: 1. Basic Fortran commands 2. Compiling, linking, and running Fortran programs 3. Plotting results with KaleidaGraph Information on these topics can be found in the physics department computer manual, available online. You are also encouraged to use the original software manuals and the web. Unit Assignment and Requirements Do each of the following: 1. Read the Fortran chapter and the sections on KaleidaGraph in the Analysis Software chapter. 2. Write a Fortran program to compute the trajectory of the simple pendulum assuming the solution is of the form θ = A cos(ω t + f), where A is the amplitude, ω is the frequency, t is the time, and f is the phase offset. Choose initial angles of 1° and 10° and a pendulum length of 1.00 m. You must output the data to a text file. Each of the files should consist of time, position, velocity, and

Upload: dotram

Post on 31-Jan-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Physics for Scientists and Engineers III Computational ...rfm/phy112lab/112labmanuals_CL2.pdf · Physics for Scientists and Engineers III Computational Physics Laboratory 2 Introduction

Illinois State University Physics 112 Department of Physics

Physics for Scientists and Engineers III

Computational Physics Laboratory 2 Introduction to the FORTRAN Compiler

Introduction The first unit introduced the Unix operating system, the BASH shell and simple shell commands, ssh and other networking commands, and the use of text editors. These are essential tools for using any Unix-based computer, including meitner, an Intel quad-core cpu. Two additional tools are required to use the computer effectively for learning and doing physics: a high-level programming language and a graphics package. The programming language used in this course is Fortran 95, a widely used high level programming languages in the sciences and engineering. For visualizing your results, you will use the KaleidaGraph data analysis and graphics software (note: you can also use GNUplot, an open source graphics program, if you prefer). With a familiarity with KaleidaGraph, you should be able to adapt to other packages you may come across in the future. Purpose

In this project, you will be introduced to the following:

1. Basic Fortran commands 2. Compiling, linking, and running Fortran programs 3. Plotting results with KaleidaGraph

Information on these topics can be found in the physics department computer manual, available online. You are also encouraged to use the original software manuals and the web. Unit Assignment and Requirements

Do each of the following:

1. Read the Fortran chapter and the sections on KaleidaGraph in the Analysis Software chapter.

2. Write a Fortran program to compute the trajectory of the simple pendulum assuming the

solution is of the form θ = A cos(ω t + f), where A is the amplitude, ω is the frequency, t is the time, and f is the phase offset. Choose initial angles of 1° and 10° and a pendulum length of 1.00 m. You must output the data to a text file. Each of the files should consist of time, position, velocity, and

Page 2: Physics for Scientists and Engineers III Computational ...rfm/phy112lab/112labmanuals_CL2.pdf · Physics for Scientists and Engineers III Computational Physics Laboratory 2 Introduction

acceleration. Plot the data in your output file using KaleidaGraph. Make plots of position, velocity, and acceleration as functions of time. What are the phase relationships between position, velocity, and time? Repeat your calculations and analysis for θ0 = 2° and dθ/dt = –0.200 rad/sec.

3. Email the instructor a short message describing one of the plots and attach an image (jpeg or png) of that plot. Note that KaleidaGraph will export plots as jpeg or png images. Alternatively, you could do a screen capture (shift-command-4 on the Mac).

4. Transfer a plot image into a word processing document and confirm that it is of

sufficiently high quality, with appropriately sized fonts, to be readable. If not, ask the instructor how to do better. You may want to insert some figure images into your write-up, for example.

5. Turn in a full write-up, following Dr. Clark’s guidelines, due at the next lab.

Page 3: Physics for Scientists and Engineers III Computational ...rfm/phy112lab/112labmanuals_CL2.pdf · Physics for Scientists and Engineers III Computational Physics Laboratory 2 Introduction

Appendix: Sample Program program pendulum ! ! Declare variables ! real*8 :: period, phi, t, amp, pi, g, l real*8 :: thet, thetd, thetdd, thet0, thet0d, w integer :: i ! ! (describe the following section of code) ! open(30, FILE = 'pend.txt') !output file for data write(30,'(A)') ' time angle ang. vel. ang. accel.' pi = 4.0d0*atan(1.0d0) g = 9.8d0 ! acceleration due to gravity in m/s2 l = 1 ! length of pendulum in m w = sqrt(g/l) ! (describe variable) period = 2.0d0*pi/w ! (describe variable) thet0 = 1.0d0*(Pi/180.0d0) ! (describe variable) thet0d = 0.0d0 ! (describe variable) amp = sqrt(thet0**2+(thet0d/w)**2) ! (describe variable) phi = atan(-thet0d/(w*thet0)) ! (describe variable) print*, 'initial angle = ',thet0,' initial ang. vel. = ',thet0d print*, 'frequency = ',w print*, 'amplitude = ',amp,' phase = ',phi ! ! (describe the following section of code) ! do i = 1,5000 t = period *dble(i)/1000.d0 thet = amp * dcos(w*t + phi) thetd = -w*amp * dsin(w*t + phi) thetdd = -w**2 *amp * dcos(w*t + phi) ! ! (describe the following section of code) ! if (mod(i,10) == 0) then write(30,'(4(e12.5,3x))') t, thet, thetd, thetdd endif enddo ! close(30) end