Ask Your Question
1

4-Digit Rounding Arithmetic:System of Equations

asked 2011-09-04 05:56:41 +0200

Mathstudent2010 gravatar image

updated 2015-01-23 21:45:08 +0200

FrédéricC gravatar image

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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2011-09-04 08:10:38 +0200

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...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-09-04 05:56:41 +0200

Seen: 1,994 times

Last updated: Sep 04 '11