The first homework of scientific programming for engineers: python programming, conjugate gradient

# Recent Commits

Commit | Author | Details | Committed | ||||
---|---|---|---|---|---|---|---|

4a51b53fd99a | azimi | minor README update | Oct 15 | ||||

315c6ededdb3 | azimi | README update and minor modofication | Oct 12 | ||||

c6b74f0901e1 | aferraro | README file in markdown | Oct 12 | ||||

4d3434cb726e | azimi | description of the second exercise in README | Oct 11 | ||||

2c64a0de8eef | azimi | initial condition modified to be fixed by default; necessary for the comparison… | Oct 11 | ||||

92cc027b4497 | azimi | minor debug | Oct 11 | ||||

b3e92c847de0 | azimi | minor debug | Oct 11 | ||||

236b90006bb6 | azimi | contours on the plot | Oct 11 | ||||

549c4a91bf42 | azimi | minor in plot function | Oct 10 | ||||

4dea52d7110c | azimi | view angle fixed to be similar to the example | Oct 10 | ||||

dd925ae60981 | azimi | 3rd part of exercise 2 is done and the plot function is a bit modified | Oct 10 | ||||

ce46cb8e664e | aferraro | added command line options | Oct 10 | ||||

6481ad4581fa | aferraro | Merge branch 'master' of ssh://c4science.ch/source/SP4E_HW1 | Oct 10 | ||||

d639b75fb62a | aferraro | added the plotting routine plotFunc | Oct 10 | ||||

e417ebc4f486 | azimi | The conjugateGradient function returns the history of the convergence | Oct 10 |

# README.md

## Minimization of a scalar function in Python

(SP4E 2018, Homework 1) Authors: Sajjad Azimi, Alessia Ferraro

- Description and usage

**optimizer.py**

The program optimizer.py finds the minimum of a given scalar function making use of the scipy.optimize.minimize module. Via the command line options, the user can choose the minimization algorithm and whether the starting point is randomly generated (See the helpmode -h by running `python optimizer.py -h`):
`-CG` (Conjugate Gradient)
`-BFGS` (Broyden-Fletcher-Goldfarb-Shannon)
`-RI` to generate a random initial condition
For example: `python optimizer -CG -RI`
Once the optimization process reaches the required tolerance a plotting routine shows both the surface and the minimization path of the chosen algorithm.

**conjugate_gradient.py**

To run conjugate_gradient.py you have to run the following command in the terminal:
`python conjugate_gradient.py`
Once you run the command, the processor uses the function which implements the linear conjugate gradient method, and finds the minimum of the function S, given in the homework description. The initial condition is a fixed point at [3.0, 1.0]. After running the program, the number of steps and the final solution are printed on the screen and the 3D plot of the surface and the path of the point during the convergence are shown in a new window. The convergence of the point is exactly like the convergence of the point in exercise 1 with the optimizer (when the initial condition is not randomly generated in the optimizer.py the initial conditions in both programs are the same).