I am trying to get myself acquainted with Maple and was fooling around with some linear algebra.
I noticed that the following commands
restart;
with(LinearAlgebra);
P:=<0.6,0.3;0.4,0.7>;
Id := IdentityMatrix(2);
A:=P-Id;
b:=ZeroVector(2);
Aug1:=<A|b>;
LinearSolve(Aug1,free='x');
produce the unexpected result $$ \begin{bmatrix} -0. \\ -0. \\ \end{bmatrix} $$
Entering the augmented matrix manually, however
Aug2:=<-0.4,0.3,0;0.4,-0.3,0>;
LinearSolve(Aug2,free='x');
does produce the result I was expecting $$ \begin{bmatrix} 0.750000000000000x_1 \\ x_1 \\ \end{bmatrix} $$
The only difference I see, is that Aug1 looks like $$ \begin{bmatrix} -0.400000000000000 & 0.300000000000000 & 0 \\ 0.400000000000000 & -0.300000000000000 & 0 \\ \end{bmatrix} $$ while Aug2 looks like $$ \begin{bmatrix} -0.4 & 0.3 & 0 \\ 0.4 & -0.3 & 0 \\ \end{bmatrix} $$
Using whattype() I already determined that both Aug1 and Aug2 have the Matrix datatype and their elements have the float datatype.
Any idea how I could produce the expected result using Aug1 ($=P-Id$)?
When you add your Matrix
A(whose entries are all of typenumeric, and at least one is a float) to yourIdthe 2x2 identity Matrix, then the result hasdatatype=float[8]and is stored in so-called hardware double precision.That is a base-2 format, in which the floats 0.3 and 0.7 cannot be represented exactly. Notice how the following values
p1andtempdiffer by a very small (but nonzero!) amount. I use Maple'sevalhfmode here, to mimic the double precision operations in question.Notice the
resis not exactly0.0.At the default values for the environment variables
Digits(10) andUsehardwareFloats(deduced) the followingLinearAlgebracomputations are done in hardware double precision.The result from
LinearSolveis indeed a single, valid solution, but the parametric answer is not obtained. That is because the linear-solving algorithm does not detect that the two rows are "close enough" to being merely elementwise negations of each other.The following provides some insight as to how that was computed.
Notice the similarity with the earlier scalar computation. Notice that the bottom row of the results from
ReducedRowEchelonFormandRowOperationare not all zero, and neither is theLMatrix returned byLUDecomposition.One way to work around this issue is to perform the computations in so-called "software floats", which in Maple means a base-10 floating-point format in which the values 0.3 and 0.7 can be stored "exactly".
With the default value of
deducedforUseHardwareFloatsthen software floats will get used ifDigitsis greater than 15. OrUseHardwareFloatscould be set tofalseand then software floats would get used, for any valid setting ofDigits.Let's re-do all those computations, with
UseHardwareFloatsset tofalse.The following provides some insight as to how that was computed.
Another way to get at a parametric solution for your example is to compute the
NullSpace(Kernel) of yourAMatrix, and form a parametrized linear combination of the (here, one) Vector in the basis.This question is about Maple programming and not about mathematics per se, and as such is off-topic in this forum. More suitable would be stackoverflow.com or www.mapleprimes.com the Maplesoft user forum.