Question: How to manage the precision of the numerical values in the printf("%a", SomeAlgebraicExpression) command ?

Hi everybody,

My worksheet begins with these two instructions (this is a notional example)
Digits := 25:
interface(displayprecision = 5):

Then the instruction  evalf(1/3+x/6)  returns  0.33333+0.16667x … which is what I had expected.

I now  want to do a formatted print of  evalf(1/3+x/6)  in some file.
Unfortunately the command  

 fprintf(fd, "%a\n", evalf(1/3+x/6)) 

generates a print with the full digits precision (0.333…..33 with 25 "3" for instance).

How could I force fprintf to print the floating point numbers with the number of digits set by interface(displayprecision = 5) ?
 
(PS : for now I have written some kind of “white elephant” stuff which works well only for very simple algebraic expressions)

Any suggestion or answer will be greatly appreciated

 


 

Please Wait...