I'm not really familiar with fortran (or our generators of fortran code), but playing around with using floats and ints can get the results you want:
On Fri, Nov 11, 2011 at 11:53 AM, vweber <[email protected]> wrote: > Dear all > > Few questions: > > 1) exectuting that >> x = symbols('x') >> z=1.0*x**(-1.0) >> print fcode(simplify(z)) > > gives > >> 1.0d0*x**-1.0d0 > > which is not fortran standard.. I would expect 1.0d0/x or x**(-1) or > in the worst case x**(-1.0d0). How can I get a better output? In [7]: fcode(S(1.0*x**(-1))) Out[7]: 1.0d0/x or the "worst case": In [6]: fcode(S(1*x**(-1.0))) Out[6]: x**-1.0d0 > > 2) executing that >> x = symbols('x') >> z=x**2 >> print fcode(simplify(diff(z))) > > gives > >> 2*x > > I would like to get 2.0d0*x instead, any hints? > Unfortunately, In [32]: fcode(S(diff(x**2.0))) Out[32]: 2.0d0*x**2.0d0/x Not really sure what to do here. > 3) executing >> x = symbols('x') >> z=1.0*x**(1.0/3.0) >> print fcode(simplify(z)) > > gives > >> 1.0d0*x**0.333333333333333d0 > > but I would like to keep the exponent as a fraction (ie > x**(1.0d0/3.0d0)) In [43]: fcode(S(1*x**(Rational(1,3)))) Out[43]: x**(1.0d0/3.0d0) > > Thanks > > V > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > > Hope that helps! -- Vladimir Perić -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
