Search code examples
parsingfortransymbolic-math

Fortran: matrix from symbolic functions


I need to transform a set of symbolic equations defining relations between \vec(a) = (a,b,c) and \vec(x) = (x,y), e.g.

a = 1./2 * x
b = -1./2 * x
c = 1./2 * y

into a matrix form so that I get the matrix A, when I write \vec(a) = A * \vec(x):

/ a \   /  1./2   0   \    / x \
| b | = | -1./2   0   |  * \ y /
\ c /   \   0    1./2 /    

Now the problem is, that the whole things needs to be in Fortran: reading the equations and transforming them to the matrix A.

I have found the module fparser (https://www.sourceforge.net/projects/fparser/) to evaluate symbolic math expressions, but I could need some help figuring out how to most efficiently build these matrices without doing too much string parsing...


Solution

  • Although it's long ago, I want to post what helped me solving the issue: I used fparser (http://fparser.sourceforge.net/).