# 4-Digit Rounding Arithmetic:System 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.130x + 6.990y == 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.

edit retag close merge delete

Sort by » oldest newest most voted

Why do you think that 8.9101 is wrong? It's correct rounding; more precisely, Sage does "rounding 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...

more