Automatic differentiation

I am working on my project on the production, in particular, on fluid dynamics, and I have a system of nonlinear equations to solve, I choose Newton's method, so I have to go through the Jacobian matix (actually a 12x12 matrix). Each element in this matrix is ​​a derivative of a function evaluated at some point; it is very difficult to write all this data manually and calculate each derivative; the system looks like this:

f 1 (x 1 , x 2 , x 3 , ..., x 12 ) = 0
f 2 (x 1 , x 2 , x 3 , ..., x 12 ) = 0
,
,
,
f 12 (x 1 , x 2 , x 3 , ..., x 12 ) = 0


Where x 1 , x 2 , x 3 are variables (temperature, pressure ... etc.)
Can I automate this operation? If this is not possible in Fortran, is it possible to use other scripting languages ​​like Python (sympy module)?

+6
source share
2 answers

Yes, using the appropriate algorithmic differentiation package. This is a method that can evaluate (in principle) arbitrary derivatives of the order of any function that you expressed as a computer program, and there are several packages for Fortran. Take a look at

http://en.wikipedia.org/wiki/Automatic_differentiation

and

http://www.nag.co.uk/pss/nag-and-algorithmic-differentiation

to start

Denial of responsibility:

1) I never used it "in anger"

2) Until recently, I worked at NAG

+3
source

Yes, you can use sympy for symbolic differentiation and print Fortran code . Another system, such as Maple, can also do this. Keep in mind that you can spend quite a bit of time computing derivatives, especially if they are not optimized, and numerical differentiation can be faster.

+1
source

Source: https://habr.com/ru/post/984252/


All Articles