Computational Physics - Department of Physics
Chapter 2 Introduction to C++ and Fortran AbstractThis chapters aims at catching two birds with a stone; to introduce to you ess ...
10 2 Introduction to C++ and Fortran Table 2.1Examples of variable declarations for C++ and Fortran. We reserve capital letters ...
2.1 Getting Started 11 Fortran C++ Program structure PROGRAM something main () FUNCTION something(input) double (int) something( ...
12 2 Introduction to C++ and Fortran returning 0 if success. The operating system stores the return value, and other programs/u- ...
2.1 Getting Started 13 Another feature which is worth noting is that we have skippedexception handlings here. In chapter 3 we di ...
14 2 Introduction to C++ and Fortran WRITE(,)'Hello World! SINE of ', r,' =', s END PROGRAMshw The first statement must be a pro ...
2.2 Representation of Integer Numbers 15 # General makefile for F90 - choose PROG = name of given program # Here we define compi ...
16 2 Introduction to C++ and Fortran C++: short int age_of_participant; Note that the (KIND=2)can be written as (2). Normally ho ...
2.2 Representation of Integer Numbers 17 http://folk.uio.no/mhjensen/compphys/programs/chapter02/cpp/program2.cpp using namespac ...
18 2 Introduction to C++ and Fortran cin >> int2; int1 = (int) pow(2., (double) int2); cout <<" 2^N2^N = "<< i ...
2.3 Real Numbers and Numerical Precision 19 ! Now we read from screen the variable int2 WRITE(*,*)'Read in the number to be expo ...
20 2 Introduction to C++ and Fortran and cos( 0. 007 )≈ 0. 99998. The first expression forf(x)results in f(x) = 1 − 0. 99998 0. ...
2.3 Real Numbers and Numerical Precision 21 ( 0 .a− 1 a− 2 ...a−n) 2 =a− 1 × 2 −^1 +a− 2 × 2 −^2 +···+a−n× 2 −n. In a typical co ...
22 2 Introduction to C++ and Fortran 1 .(a− 1 a− 2 ...a−n) 2 is always truncated at some stagendue to its limited number of bits ...
2.3 Real Numbers and Numerical Precision 23 Instead of usingx−andx+as the machine numbers closest tox, we introduce the relative ...
24 2 Introduction to C++ and Fortran 2 −r≤ 1 − c b ≤ 2 −s, (2.2) then at mostrand at leastssignificant binary bits are lost in t ...
2.4 Programming Examples on Loss of Precision and Round-offErrors 25 0 E− 10 , so that for a certain value ofx> 0 , there is ...
26 2 Introduction to C++ and Fortran xexp(−x) Series Number of terms in series 0.0 0.100000E+01 0.100000E+01 1 10.0 0.453999E-04 ...
2.4 Programming Examples on Loss of Precision and Round-offErrors 27 xexp(−x) Series Number of terms in series 0.000000 0.100000 ...
28 2 Introduction to C++ and Fortran ment inside a do loop. Fortran has also if statements as in C++. The IF construct allows th ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf