Difference between revisions of "CoCoA:HowTo:Round Coefficients"

From ApCoCoAWiki
 
m
Line 12: Line 12:
 
   S;
 
   S;
  
code by [[User:Dheldt|dheldt]] 09:23, 23 Jun 2005 (CEST)
+
code by [[User:Dheldt|dheldt]], 23 Jun 2005 (CEST)
  
 
== second version, only rounding coefficients ==
 
== second version, only rounding coefficients ==
Line 22: Line 22:
 
   S;
 
   S;
  
code by [[User:Dheldt|dheldt]] 09:23, 23 Jun 2005 (CEST)  
+
code by [[User:Dheldt|dheldt]], 23 Jun 2005 (CEST)  
  
 
==Examples==
 
==Examples==

Revision as of 11:39, 12 July 2005

About

CoCoA 4 computes polynomials either Q or in Z/(p). In case you have polynomials in Q and you do some computations with them, after some time their coefficients probably look quite ugly (ToDo: Add Example). To get a feeling for the coefficients, it may be quite handy to get a rounded value instead of these loooong fractions. Their is no code inside CoCoA to do this automatically, but you can do it quite easy, using CoCoA's FloatApprox or FloatStr functions.

first version, converting to string

 P := x^2 + 11/10 y + 1/3 z;
 
 S := Sum(Flatten([ ['( ',FloatStr(LC(M)),'*',Sprint(LT(M)),') +'] | M In Monomials(P)]));
 
 S;

code by dheldt, 23 Jun 2005 (CEST)

second version, only rounding coefficients

 P := x^2 + 11/10 y + 1/3 z;
 
 S := Sum([ FloatApprox(LC(M),1/10^3)LT(M) | M In Monomials(P)]);
 
 S;

code by dheldt, 23 Jun 2005 (CEST)

Examples

ToDo