how to make the output of LinearSolve(...) be given to 3 significant figures?

This is mainly an aesthetic thing, but I'm finding an interpolating quartic polynomial given some data points, so I set up a Matrix system of linear equations etc, but I want the output solution vector (i.e. the solutions for the coefficients of x0, x1, x2, etc.) to be to 3sf. I have tried putting evalf[3](LinearSolve(A,b)); but that doesn't seem to work. Even if I change Digits, (which isn't ideal anyway as I only want output to be to 3sf temporarily) the values in the vector solution are still to 10sf.

display precision

interface(displayprecision=3);

should do the trick.

 

 

displayprecision seems to give me 3dp, not 3sf

ah, I'd never heard of this. This seems to give me 3 decimal places rather than 3 significant figures, and one of the numbers is  -0.00174999999999889480,  so if this comes out as -0.002, it does make quite a big difference. Sorry to be pedantic about a small thing, but it is surprisingly difficult to achieve i'm finding!

evalf(v,3)

Which version of Maple are you using?

The following code gives 3sd for me on Maple 11, Windows.

 

A := LinearAlgebra[RandomMatrix](3,3);
b := LinearAlgebra[RandomVector](3);
soln :=LinearAlgebra[LinearSolve](A,b);
evalf(soln,3);
 

 

I do not know if this will work, but you could try,

interface(elisiondigitsafter=3);

Does someone know what this does?

I'm using Maple 11 on

I'm using Maple 11 on Windows vista.

I'm getting really weird results, I've tried it using evalf[3](soln); and this sort of worked; it gave me 0.00175000000000000004, which is rounded from the actual value, but there's that inexplicable 4 at the end! evalf gives it *almost* to 3sf but then adds or subtracts about 10-20 for no apparent reason.

 

Could it be that I'm already within the LinearAlgebra package, and that's messing some numerical things up? By that I mean that instead of writing LinearAlgebra[...] on every line, i wrote with(LinearAlgebra); on the first line of the worksheet. Will I be able to fix this without leaving the LinearAlgebra package?

acer's picture

hardware double precision artefacts

The strange digits at the very end of the displayed numbers in the results are merely artefacts and can be safely ignored.

If you lprint() the results you will see that the Vector (or Matrix) in question has a float[8] datatype. That means hardware double precision, and comes about because those floating-point results are computed using a precompiled library (external to the main Maple kernel). Now, hardware double precision is a base-2 (binary) representation, but Maple shows the results in base-10 so that we can recognize them.

Those training strange digits are artefacts of the conversion from the underlying base-2 stored value to the (nearest possible) base-10 number. Notice how those artefacts lie in decimal digits places even beyond the 14th or 15th, despite that being past trunc(evalhf(Digits)). Personally, I would prefer that those digits weren't displayed at all, and that only trunc(evalhf(Digits)) digits were shown for float[8] datatype Vector/Matrix/Array objects.

acer

Rounding error

I agree w/ acer.  It may not be nice, but you have to live with those strange digits.

don't worry about it any

don't worry about it any more, for some reason it was having problems rounding numbers inside a vector, so i dotted itt with <1,x,x^2,x^3,x^4> to turn it into a polynomial then used evalf[3] and it worked fine.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}