LABORATORY OF COMPUTATIONAL PHYSICS I

Course objectives

GENERAL OBJECTIVES: The main objective of the course is to teach students the use of computers for solving some fundamental problems in physics. This is achieved by teaching students some advanced elements of the C programming language, along with several algorithms which, although simple, are widely applicable in different contexts. At the end of the course, students will have acquired a sufficiently in-depth knowledge of the C programming language and other operational tools useful for data analysis and their graphic representation. They will have acquired the skills necessary to solve physics problems of medium difficulty with the computer and to autonomously implement algorithms of a certain complexity. SPECIFIC OBJECTIVES: A - Knowledge and understanding OF 1) Advanced elements of C programming (dynamic allocation, struct, recursion) OF 2) Basic and advanced algorithms for the integration of ordinary differential equations, for the generation of pseudo-random numbers, and for the study of simple stochastic processes (random walk, reticular gas and percolation) OF 3) Understand a program written in C language B - Application skills OF 4) Be able to implement an algorithm in C language OF 5) Knowing how to solve, with the use of computers, medium difficulty physics problems that are described by differential equations or by a simple stochastic process OF 6) Being able to find errors in a program written in C language (debugging) and knowing how to correct them OF 7) Be able to perform, with IT tools, simple data analysis (e.g. performing averages and the calculation of the error for independent measurements), and their graphical representation C - Autonomy of judgment OF 8) Knowing how to independently evaluate if a program written in C language correctly executes a given algorithm and if this implementation is efficient D - Communication skills OF 9) Knowing how to discuss critically the choices made in the implementation of a given algorithm in a program written in C language OF 10) Knowing how to present in written form the results of the study of a physical problem carried out numerically using the computer E - Ability to learn OF 11) Have the ability to consult the description of a new algorithm or understand a C language program written by others

Channel 1
PAOLO PANI Lecturers' profile
PAOLO PANI Lecturers' profile

Program - Frequency - Exams

Course program
More info: https://elearning.uniroma1.it/course/view.php?id=2315 The first part of the course is devoted to the numerical solution of ordinary differential equations and the introduction of advanced elements of C programming [about 15 hours]. The second part of the course illustrates the generation of pseudo-random numbers and their use in the simulation of some stochastic processes, which are then studied in detail: random walk, reticular gas and percolation [about 15 hours]. The course includes laboratory activities in which students write their own codes in C language to study the problems discussed during the lectures, implementing the algorithms described by the lecturer [about 30 hours].
Prerequisites
It is essential to know the basics of programming in C language provided in the Computing Laboratory course (first year, bachelor degree in Physics( It is important to know how to use basic IT tools, such as a file editor for writing programs and a C compiler It is useful to have a computer with a Unix / Linux environment and to be able to perform basic operations in this environment (for example, transferring a file)
Books
“Scientific programming: C-language, algorithms and models in science” Luciano Barone, Enzo Marinari, Giovanni Organtini e Federico Ricci-Tersenghi World Scientific, Singapore (2013)
Teaching mode
50% of the course is taught in standard classroom lectures mainly carried out on the blackboard and for the remaining half of the time in a computer lab. During the lectures, the teacher illustrates the physical problems at hand and the way in which they can be studied with numerical simulations, also presenting different numerical algorithms to solve a given problem and providing several details on the technical implementation in C language. In the computer lab, students put into practice all the notions provided during the lectures developing from scratch their own program in C language and finally using it to study the specific physical problem discussed during the lectures. During the lab, the lecturer and teaching assistants provide suggestions on writing programs and on how to carry out numerical simulations. Participation in all laboratory sessions is mandatory.
Frequency
Labs are mandatory (https://elearning.uniroma1.it/course/view.php?id=2315)
Exam mode
The evaluation of the students and their final grade is based on the following three elements (with similar weights): 1) participation and performance during the laboratory sessions, including the correctness and readability of written programs, as well as the goodness of the data analysis, and the clarity of the graphical representations of the results; 2) the assessment of a first ongoing test which is assigned around the middle of the course and is usually carried out independently by the students over a week or so; 3) the evaluation of a second ongoing test which is carried out towards the end of the course in the computer labs of Sapienza. Obtaining a sufficient evaluation in all three above elements is a necessary condition to be able to access any exam session. In order to achieve a sufficient evaluation in the exercises and in the ongoing tests students should demonstrate that: (i) they can correctly program the algorithms discussed during the lectures; (ii) they know how to identify errors in a code written in C language; (iii) they know how to use such programs for the study of a physical problem, producing a correct data analysis and a valid graphic presentation and discussion of the results.
Bibliography
“Scientific programming: C-language, algorithms and models in science” Luciano Barone, Enzo Marinari, Giovanni Organtini e Federico Ricci-Tersenghi World Scientific, Singapore (2013)
Lesson mode
50% of the course is taught in standard classroom lectures mainly carried out on the blackboard and for the remaining half of the time in a computer lab. During the lectures, the teacher illustrates the physical problems at hand and the way in which they can be studied with numerical simulations, also presenting different numerical algorithms to solve a given problem and providing several details on the technical implementation in C language. In the computer lab, students put into practice all the notions provided during the lectures developing from scratch their own program in C language and finally using it to study the specific physical problem discussed during the lectures. During the lab, the lecturer and teaching assistants provide suggestions on writing programs and on how to carry out numerical simulations. Participation in all laboratory sessions is mandatory.
CHIARA CAMMAROTA Lecturers' profile
CHIARA CAMMAROTA Lecturers' profile
Channel 2
CARLO MANCINI TERRACCIANO Lecturers' profile
CARLO MANCINI TERRACCIANO Lecturers' profile
FABIO LEONI Lecturers' profile
FABIO LEONI Lecturers' profile
Channel 3
VINCENZO MARINARI Lecturers' profile
VINCENZO MARINARI Lecturers' profile

Program - Frequency - Exams

Course program
ORDINARY DIFFERENTIAL EQUATIONS MODULE (30 hours) Integration of differential equations with initial conditions. Euler method. Local error and global error. Harmonic oscillator. Euler-Cromer method. Study of the integration error. The prototype of the main function and the command line arguments. Input / output management: stdin, stdout, stderr. Input and output redirection from the command line. Remote file transfer between machines. Use of gnuplot to generate data graphs. Stability: the case of oscillations and exponential growth / decrease. Stability properties of Euler and Euler-Cromer methods. The role of characteristic time scales. Integration methods: Reversibility in the Euler-Cromer method and Verlet method. Conservation laws along the approximate trajectories of the harmonic oscillator. Simple pendulum. Measurement of the period and study of small oscillations. Oscillations with linear damping. Estimation of the decay rate and critical damping. Use of precompiler macros for conditional compilation: #if, #elif, #else, #endif, #ifdef. The -D option of the gcc compiler. Conditional compilation and macro functions. Insights on the use of gnuplot: graphs in a bilogarithmic scale ("set log"), definition of functions of an independent variable, adjust the parameters of the functions with gnuplot ("fit via"). Runge-Kutta methods of order II and IV. C: struct structures, struct pointers. Forced pendulum. Elements of chaos. Poincaré section. Basins of attraction. Bifurcation diagrams. Motion in a plane. Coupled equations. Motion of planets around a fixed star. Astronomical units of measurement. Calculation of the period of a closed orbit in the phase space. Considerations on the precision of the floating-point calculation in the choice of the integration step. Three-dimensional graphics with gnuplot. Stability due to oscillations and relative error in the energy calculation with Runge-Kutta methods. RANDOM WALKS MODULE (20 hours) Dynamical memory allocation: malloc (), calloc (), realloc (), free (), sizeof (). Brownian motion. Random Walk in one dimension. Generation of pseudo-random numbers with the linear congruence method. Generation of random numbers with any distribution: inversion of the cumulative, "accept or reject" method and Box-Müller transformation. Notable generators (for good or for bad) and commonly used ones: Minimal Standard, Randu, purely multiplicative of the Ecuyer. C library functions: rand (), lrand48 (), drand48 () Building the histogram of the values ​​of a one-dimensional random walk at fixed time. Binning of a histogram. Random walk in multiple spatial dimensions. Probability of return. Review of positional numerical systems. Hex system. Representation of integers on the calculator. Bitwise operators "&", "|", "^", "~". Bit shift operators "", "
Prerequisites
Basic knowledge of unix, bash and the syntax of C
Books
L.Barone, E. Marinari, G. Organtini, F. Ricci Tersenghi, "Scientific programming: C-language, algorithms and models in science", World Scientific, Singapore (2013)
Teaching mode
Approximately 30 hours of teaching in class and 10 practical experiences in the lab (https://elearning.uniroma1.it/course/view.php?id=2315)
Frequency
Attending the numerical lab is mandatory.
Exam mode
COMPUTATIONAL PHYSICS LABORATORY 1 STRUCTURE OF THE EXAMINATIONS The Computational Physics Laboratory 1 course (first semester of the second year of the Bachelor's Degree in Physics) is a theoretical and practical course, which includes mandatory attendance of computational laboratory sessions. The course includes a total of approximately thirty hours of lectures and approximately thirty hours of computational laboratory attendance. Profitable participation in the laboratory sessions is mandatory: any unavoidable absences can be made up in agreement with the course instructors. Laboratory work is carried out in groups, each composed of two students, but it is naturally crucial that both members of the group contribute actively to the common work. The characteristics of the course require an articulated form of assessment, different from the assessment of courses that take place only in the classroom. The fundamental components are the evaluations of the two intermediate tests, both mandatory, and the evaluation of the work done in the laboratory, both during the sessions and in its final form, with an assessment of the codes and results produced in the lab. The first intermediate test is usually offered around the middle of the course (early November) in class on the computer. The second intermediate test usually takes place the week after the last laboratory session. Like the first, it is an individual test to be taken on the computer in our computational laboratories, and serves to demonstrate the skills acquired during the laboratory course. The main part of the test usually involves correcting a code and/or writing code fragments or short complete codes, and finally producing plots, fits, and histograms. In cases of certified force majeure, such as illness or absolutely unavoidable commitments, the student can take a make-up test. Both intermediate tests may contain "theoretical" questions relating exclusively to the material discussed during the lectures and included in the syllabus. The codes produced in the laboratory are evaluated, both during the individual sessions and at the end of the course in the definitive form in which they are officially submitted. The correctness, completeness, and cleanliness of the codes, their efficiency, as well as the conclusions reached with those codes (figures and data) are assessed. In this case, explanatory reports are neither required nor expected. The final grade for "laboratory exemption" is composed of a combination of the grades discussed in the previous paragraphs, with different weights, which may vary depending on the actual difficulty of the tests presented (typically, as an order of magnitude, the first test and the second test will have weights close to 0.3 for the first and 0.4 for the second, and the laboratory assessments will have a total weight close to 0.3). Obtaining a passing grade for laboratory exemption certifies that the laboratory was completed successfully and is a necessary condition for passing the exam. Those who do not obtain the laboratory exemption statement have not achieved a level of proficiency that allows them to pass the exam and will have to attend the laboratory sessions again in a future academic year. The intermediate tests of the course are mandatory precisely because they are the main assessment tool, aimed at certifying the student's actual learning during the laboratory. As mentioned, those who were absent for serious reasons can make them up immediately after the date of the tests themselves. However, the tests cannot be repeated at other times of the year because they are intermediate tests and are an integral part of the laboratory, which concludes with the end of the course. In most cases, the final "laboratory exemption" grade is proposed to the students, who can accept it as their final grade. For students who accept the grade, it is recorded at the first available exam session, without further checks of the knowledge acquired. Only in some cases, where the results of the intermediate tests, although potentially sufficient, do not provide clear evidence of the level of knowledge and skills reached by the student, a final oral-practical examination is required. These cases are individually motivated in detail. If it is necessary to take an additional oral-practical test, or if the student decides not to accept the proposed grade as the final grade to be recorded, it is possible to take the oral-practical test in all the sessions provided for by the regulations and set by the instructors. In these cases, the "laboratory exemption" grade, which will remain unchanged and valid for the entire academic year, will be averaged with the result of the oral-practical exam, and to pass, this average must reach a sufficient level. The oral-practical test covers both the theoretical topics contained in the syllabus and illustrated during the lectures, and programming and debugging practices that may be carried out on the computer during the oral-practical exam.
Bibliography
“Numerical Recipes in C”, Press, Teukolsky, …
Lesson mode
Approximately 30 hours of teaching in class and 10 practical experiences in the lab (https://elearning.uniroma1.it/course/view.php?id=2315)
MATTEO NEGRI Lecturers' profile
MATTEO NEGRI Lecturers' profile
  • Lesson code10616303
  • Academic year2025/2026
  • CoursePhysics
  • CurriculumFisica applicata
  • Year2nd year
  • Semester1st semester
  • SSDFIS/02
  • CFU6