8

I am working on my project of graduating, particularly, about fluid dynamics and I have a system of non-linear equations to solve, I choose the Newton's method so I have to pass through the Jacobian of the matix (actually 12x12 matrix). Every element in this matrix is the derivative of the function evaluated at some point, it's very difficult to write all of these manually and calculate each derivative; the system looks like:

f1 (x1, x2, x3, ..., x12) = 0
f2 (x1, x2, x3, ..., x12) = 0
.
.
.
f12 (x1, x2, x3, ..., x12) = 0


Where x1, x2, x3 are the variables (Temperature, pressure ...etc)
Can I automate this operation? If it's not possible in Fortran, can I use other scripting languages as Python (sympy module)?

ali_m
  • 71,714
  • 23
  • 223
  • 298
Syntax_ErrorX00
  • 213
  • 3
  • 7
  • 1
    You might want to take a look at [Theano](http://deeplearning.net/software/theano/) – ali_m Mar 25 '15 at 20:05
  • 1
    If you care about performance (accuracy and runtime) then you'll likely want to write the derivatives out manually – David Heffernan Mar 25 '15 at 21:04
  • If it's Fortran, then I can vouch for my own code (see my profile), which can do what you want. Also have a look at other software under the wiki link, as some might be easier to use than others. First order reverse mode AD is probably what you need. – Raul Laasner Mar 25 '15 at 23:00
  • [Here](http://www.autodiff.org/?module=Tools&language=Fortran77) is another list of Fortran alternatives. – Anders Gustafsson Mar 26 '15 at 06:28

2 Answers2

4

Yes, by use of an appropriate algorithmic differentiation package. This is a method which can evaluate (in principle) arbitrary order derivatives of any function you have expressed as a computer program, and a number of packages exist 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 get started

Disclaimers:

1) I have never used it "in anger"

2) Until recently I worked for NAG

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
  • Thanks sir, I can do the automatic differentiation numerically, ( using the derived Types and the overloading of operators), this works for sample functions which are defined at the evaluated points, but usually, this is not the case, where the function is more complex; if it's undefined at some points. – Syntax_ErrorX00 Mar 25 '15 at 21:21
1

Yes, you can use sympy for symbolic differentiation and for printing out Fortran code. Other system such as Maple can also do this. Be aware that you can spend quite a lot of time calculating derivatives, especially if these are not optimized, and numerical differentiation could be faster.