Automatic differentiation

落爺英雄遲暮 提交于 2019-12-23 07:51:47

问题


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)?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/29265164/automatic-differentiation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!