//Aarhus University / Physics / Subatomic / Theory >

Practical Programming 2018 and [Numerical Methods 2018]

[ ./lectures | ./examples | Literature | Plan: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 ]
old homepages: [ Practical programming 2017 | Numerical methods 2017 ]

NB

Schedule

Plan

  1. [top] Prerequisite: access to a POSIX system. You have (at least) the following options:
    1. Install Ubuntu. Either directly on your laptop (the default and supported option) or as a virtual machine (VirtualBox is a popular hypervisor). The latest version is 17.10. The latest long term support version is 16.04.
    2. Most of other Linux-based systems like Debian or Fedora—but not Android per se—would do just as well. Some minor details might differ.
    3. MacOS with homebrew is a possibility. It is FreeBSD-based though, not Linux, therefore some details are different from Ubuntu.
    4. Microsoft Windows with Cygwin is a possibility. Less explored.
    5. Android with termux. Unexplored.
    6. An account on a POSIX server and a laptop to ssh to your account. You might need to manually install some packages though.
  2. [top]

    Lectures
    1. Introduction;
    2. UNIX/POSIX systems;
    3. C programming language;
    4. Free/Open software.
    Exercises
    1. Learn how to start a terminal.
    2. Read about the man utility. Run man man and read the DESCRIPTION of the utility in your system.
      Hints: man usually uses less as the default pager; you quit from less by pressing the q-key.
    3. Learn the following commands (file utilities) from the GNU Core Utilities: cp, ls, mkdir, mv, rm, and the bash built-in command cd.
      Hint: type, for example, man 1 mkdir in your terminal or into Google-search in your browser.
    4. Read about the command line completion.
    5. Install your favourite text editor. If you don't have one, install the Nano text editor with the command
      sudo apt install nano
    6. Learn to create, save, and edit text files with your favourite text editor.
    7. Install the GNU C compiler — gcc — with the command
      sudo apt install build-essential
    8. Answer questions 0.
    9. Do exercise "hello". See also C Programming/Intro exercise.
      Hint: examples/hello.
    10. Hints
      • You quit from man by pressing q.
      • Directory abbreviations:
        ~ home directory
        .. parent directory
        . current working directory
        $HOME home directory
      • cd - changes into the previous directory.

  3. [top] [lectures/2]

    Lectures
    1. Structure of a C program; Basics of compilation;
    2. Variables and basic data types: char, int, float, double, long double, complex;
    3. Operators +,-,*,/;
    4. Simple output with the printf function;
    5. C math functions, math library (remember -lm); type-generic math tgmath.h.
    Exercises
    1. Read note "C-program".
    2. Read note "printf".
    3. Also read:
    4. Answer questions-1.
    5. Do exercise-math. Hints: digits.
    6. Hints:
      • In bash prompt and keys scroll over the previously issued commands.
      • In bash prompt !text runs the latest command that begins with text. Useful for issuing the same command again.


  4. [top] [lectures/3]

    Lectures

    1. Make utility and makefiles;
    2. C-language: conditional statements if, switch and loops while, for, do-while;
    3. C-language: Scope of variables: file, function, block.

    Exercises

    1. read: note "make";
    2. read: note "scope";
    3. read: C control structures;
    4. read: GNU make manual → Introduction To Makefiles.
    5. Also read:
    6. (Optional) Install additional man-pages with the command

      sudo apt-get install manpages-posix manpages-posix-dev

    7. Create a makefile for your "math" exercise and re-make the exercise using the make utility.
      Hint: examples/hello.

      From now on all your exercises (and also the examination project) must be managed using makefiles.

    8. Answer questions-2.
    9. Make exercise-epsilon. Hint: examples/epsilon.
    10. Hints:
      • If you have GNU make version 3.82+ and you don't like your recipies to start with tabulator-sign, you can do .RECIPEPREFIX := ;.
      • For nano users: you can indicate the invisible tabulator-signs with a color by adding the following lines to your ~/.nanorc,
        syntax "makefile" "[Mm]akefile"
        color white,magenta "	"
        
        where the character in between the quotation marks in the second line should be the tabulator sign and where the colors are free for you to choose.

  5. [top] [lectures/4] Pointers; Arrays and structs.

  6. [top] [lectures/5] Passing functions as arguments; Simple input and output; Streams and redirections.
  7. [top] [lectures/6] C-preprocessor; building a program from functions in different C-files; simple printf-debugging (tracing); gnuplot/pyxplot.

    1. Make the folder with your homeworks (and, later, the examination project) visible in the internet via a browser. There are several possibilities:
    2. Note "printf debugging".
    3. Also:
    4. Install Gnuplot and/or Pyxplot on your box.

      On MacOS with homebrew you can probably use the command

      brew install gnuplot
      
      For interactive usage include options --with-qt and/or --with-x11.

      On Debian based systems, like Ubuntu, the command is

      sudo apt-get --yes install gnuplot
      
      and/or
      sudo apt-get --yes install pyxplot gv
      
      The --yes option automatically answers 'yes' on all questions apt-get might ask.

      The two plotting utilities have very similar scripting languages but otherwise are somewhat different. Pyxplot uses LaTeX to render all text on the plot which is rather convenient. Gnuplot has more terminals. Look at their web-pages, gnuplot and pyxplot (specifically, the examples), and choose the one you like most (or both).

      Note: it seems the developement of pyxplot has stagnated at the moment, therefore gnuplot might indeed be a better option.

    5. Questions 5.
    6. Problems "io-gnuplot". Hints: examples/io-gnuplot.

  8. [top] [lectures/7] GNU Scientific Library (GSL): installation, including, linking; special functions; vectors and matrices.
    1. Install GSL on your box. First search for the GSL developement library in you system,
      apt-cache search libgsl | grep development
      
      It should return either libgsl0-dev or libgls-dev, depending on your system. Install this package,
      sudo apt-get install libgsl0-dev
      
      or
      sudo apt-get install libgsl-dev
      
      The HomeBrew users should (apparently) use the command
      brew install gsl
      

      Alternatively, you can download the source code and build the library on your box. It will probably take more time though.

    2. Read the GSL manual chapters 'Introduction', 'Using the library', 'Vectors and Matrices', and 'Eigensystems/Real Symmetric Matrices'.
    3. Questions 6.
    4. Problems "GSL". Hints: examples/gsl.

  9. [top] [lectures/8]
    GSL: vectors and matrices; vector and matrix operations; BLAS; Ordinary Differential Equations Initial Value (odeiv) problem.
  10. [top] [lectures/9]
    GSL: Numerical integration.
    1. Read the Introduction to numerical integration in GSL manual;
    2. Learn the interfaces to the following structures and functions:
      • gsl_function (providing the function to integrate)
      • gsl_integration_qag (adaptive Gauss-Kronrod integrator)
      • gsl_integration_qags (singular integrand)
      • gsl_integration_qagi (infinite interval)
      • gsl_integration_qagiu (infinite upper interval)
      • gsl_integration_qagil (infinite lower interval)
      • gsl_integration_cquad (new fashionable algorithm)
    3. Look at the 'Numerical Integration Examples'.
    4. Questions 9.
    5. Problems "integ". Hints: lectures/integ-gamma.

  11. [top] [lectures/10]
    GSL: multidimensional root-finding (nonlinear equations).
  12. [top] [lectures/multimin-higgs]
    GSL: Multidimensional minimization.
  13. [top] [lectures/multimin-higgs] LATEX: basics; document structure; importing graphics.
    1. Install LaTeX on your system:
      1. Debian based systems: install Tex Live distribution with the command
        sudo apt-get install texlive texlive-latex-extra
        
      2. MacOS with HomeBrew: install MacTeX distribution. It seems that you first need to install homebrew cask and then
        brew cask install mactex
        
        or
        brew cask install basictex # allegedly a small but functional version of MacTeX
        
    2. Read the chapter 'Basics', 'Document Structure', and 'Importing Graphics' in the LaTeX wikibook.
    3. Another interesting reading is A brief and concise description of RevTeX 4 package.
    4. Browse through the sections 'Mathematics', 'Advanced mathematics', 'Floats, Figures and Captions', 'Labels and Cross-referencing', and 'Bibliography Management/Embedded system' in the LaTeX wikibook.
    5. Learn how to do the following things in LaTeX: math; displayed equation; floating figures and tables; cross-references; the bibliography.
    6. Questions 8.
    7. Problems "latex". Hints: lectures/latex.

  14. [top] [lectures/13] Tips on programming and debugging; FAQ.
    1. Good coding style:
      1. The code is segmented into small methods/functions spanning no more than a screenful.
      2. The names of functions, structures.members, and variables are meaningful and self-describing.
      3. The logic of the code is easy to follow and easy to modify (by somebody else); only a small number of comments are needed in a good code.
      4. Defensive programming: #include<assert.h> and use assertions plentifully: you can easily disable all assertions by simply recompiling the code with -DNDEBUG c-flag:
        CFLAGS += -DNDEBUG
        
    2. Problem "debug".
    3. The "big programming exercise":
      • note your serial number in our spreadsheet and make the corresponding exercise from this list. If your serial number is larger, than the the number of exercises, continue counting from the first exercise.
      • The target of the exercise should be report.pdf (or simlar) with your report. The report should be prepared in LaTeX and should contain a short description of the problem, the way you have solved it, and a figure, prepared in gnuplot, figure to illustrate that the problem has been solved correctly.
      • make clean should correctly clean the project.
      • make clean; make should correctly rebuild the project.
      • The project must be built before submission.
Lecturer:
Dmitri Fedorov
Literature:
  1. Wikibooks, C programming (the link also provides a PDF version).
  2. Wikipedia article C syntax.
  3. GNU Scientific Library manual.
  4. Gnuplot documentation.
  5. Pyxplot User's Manual.
  6. Wikibooks, LaTeX.
Links:
Wikipedia

Copyleft © D.V.Fedorov (fedorov @ phys au dk)

Search wikipedia for c language.