ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 04 Sep 2011 01:10:38 -05004-Digit Rounding Arithmetic:System of Equationshttps://ask.sagemath.org/question/8305/4-digit-rounding-arithmeticsystem-of-equations/I am given this system of equations:
1.130x - 6.990y = 14.20
1.013x - 6.099y = 14.22
In sage I input
sage: y = var("y")
sage: solve ([1.130*x + 6.990*y == 14.20, ... etc ], x,y )
it spits out 4264/63, 1684/189
for x,y I now input
sage: round((4264.0/63.0), 4) --> for x and same thing for y, using 1684.0 / 189.0.
Giving me 8.9101, yet this answer seems to be wrong.
My question is where can I found out how to do 4 digit rounding arithmetic using sage? or Am I doing something wrong with the code. Sat, 03 Sep 2011 22:56:41 -0500https://ask.sagemath.org/question/8305/4-digit-rounding-arithmeticsystem-of-equations/Answer by Dima for <p>I am given this system of equations:</p>
<p>1.130x - 6.990y = 14.20
1.013x - 6.099y = 14.22</p>
<p>In sage I input
sage: y = var("y")
sage: solve ([1.130<em>x + 6.990</em>y == 14.20, ... etc ], x,y )
it spits out 4264/63, 1684/189
for x,y I now input
sage: round((4264.0/63.0), 4) --> for x and same thing for y, using 1684.0 / 189.0.
Giving me 8.9101, yet this answer seems to be wrong.
My question is where can I found out how to do 4 digit rounding arithmetic using sage? or Am I doing something wrong with the code. </p>
https://ask.sagemath.org/question/8305/4-digit-rounding-arithmeticsystem-of-equations/?answer=12621#post-id-12621Why do you think that 8.9101 is wrong? It's correct rounding; more precisely, Sage does ["rounding half-up"](http://en.wikipedia.org/wiki/Rounding#Round_half_up), and this is correct rounding.
Do not mistake it for truncation.
By the way, solving linear systems by solve() isn't the best; I'd use the linear algebra functionality, i.e.
sage: A=matrix(RDF,[[1.130, -6.990],[1.013, -6.099]])
sage: A.solve_right(vector(RDF,[14.20,14.22]))
(67.6825396825, 8.91005291005)
I've put RDF qualifiers to speed things up for Sage, so it does not have to figure out the type to use.
You can use just
sage: A=matrix([[1.130, -6.990],[1.013, -6.099]])
sage: A.solve_right(vector([14.20,14.22]))
too, but this would slow Sage down if you do lots of such things with big matrices...
Sun, 04 Sep 2011 01:10:38 -0500https://ask.sagemath.org/question/8305/4-digit-rounding-arithmeticsystem-of-equations/?answer=12621#post-id-12621