Fortran representation of symbolic expression
Generate Fortran code from the symbolic expression
syms x f = log(1+x); fortran(f)
ans = ' t0 = log(x+1.0D0)'
Generate Fortran code for the 3-by-3 Hilbert matrix.
H = sym(hilb(3)); fortran(H)
ans = ' H(1,1) = 1.0D0 H(1,2) = 1.0D0/2.0D0 H(1,3) = 1.0D0/3.0D0 H(2,1) = 1.0D0/2.0D0 H(2,2) = 1.0D0/3.0D0 H(2,3) = 1.0D0/4.0D0 H(3,1) = 1.0D0/3.0D0 H(3,2) = 1.0D0/4.0D0 H(3,3) = 1.0D0/5.0D0'
Write generated Fortran code to a file by specifying the
File option. When writing to a file,
fortran optimizes the code using intermediate variables
t1, .… Include comments in the
file by using the
syms x f = diff(tan(x)); fortran(f,'File','fortrantest')
t0 = tan(x)**2+1.0D0
Include the comment
Version: 1.1. Comment lines must be
shorter than 71 characters to conform with Fortran 77.
*Version: 1.1 t0 = tan(x)**2+1.0D0
f— Symbolic input
Symbolic input, specified as a symbolic expression.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'File'— File to write to
File to write to, specified as a character vector or string. When
writing to a file,
fortran optimizes the code using
intermediate variables named
'Comments'— Comments to include in file header
Comments to include in the file header, specified as a character vector, cell array of character vectors, or string vector. Comment lines must be shorter than 71 characters to conform with Fortran 77.
MATLAB® is left-associative while Fortran is right-associative. If
ambiguity exists in an expression, the
must follow MATLAB to create an equivalent representation. For example,
(a**b)**c in Fortran.