Items tagged with linearalgebra linearalgebra Tagged Items Feed

Simple test of GaussianElimination function

Why doesn't this work? 

Also can I just confirm that for GaussianElimination (according to the help this uses LUDecomposition function with the output=['U'] option) the input is the augmented matrix of the system, the coefficient matrix augmented with the RHS)

In a separate test I got an example working using this code, but I've never seen this syntax before for A Matrix (using << it seems?)

 

Thank you for your help.

 

 

ORIGINAL ATTEMPT

with(LinearAlgebra):

A := matrix(3, 3, [-3, 2, 1, 1, -2, 1, 1, 2, -3]);

Matrix(3, 3, {(1, 1) = -3, (1, 2) = 2, (1, 3) = 1, (2, 1) = 1, (2, 2) = -2, (2, 3) = 1, (3, 1) = 1, (3, 2) = 2, (3, 3) = -3})

(1)

GaussianElimination(A)

Error, (in LinearAlgebra:-GaussianElimination) invalid input: LinearAlgebra:-GaussianElimination expects its 1st argument, A, to be of type Matrix() but received A

 

``

 

Download gauss_elimination_2.mw

I want to analyze the runtimes on certain Linear Algebra functions in Maple, so I need a (large) set of matrices to input into these functions.

I have written the below code, which does succesfully generate a file of matrices:

The resulting file looks like:

However, I am unable to read the matrices from this file back into Maple. When using the code below, I get an error.


I think the error is that %a in fscanf scans up to the next whitespace, so the spacing in Matrix(3, 3, [[9,1,-4],[-5,6,-10],[-10,-4,-4]]) is throwing fscanf off. Do you guys know of any way I can fix this?

 

Or, is there a better way for me to generate these matrices so that they can be easily read into Maple? I've considered using ImportMatrix/ExportMatrix, but I believe that they only work for a single matrix, not the numerous ones that I would need. 

I am trying to find the optimal routing probabilities in a Maple procedure where the Mean Value Analysis is used to compute the queueing values. The Maple code is below. It first tries to compute the visit ratios where the probability routing values are the decision variables. There is one specified constraint on the sum of the probability decision variables.

 

restart;
interface(warnlevel=0): interface(displayprecision = 4): with( plots ):
with(linalg):with( Optimization ); with(Student[NumericalAnalysis]):
[ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize,

NLPSolve, QPSolve]
f:=proc(x1,x2,x3)
global T,lambda,nq,u;
local i,j,pop,Sum;
n:=3;N:=2;M:=3;
#
# Gauss-Seidel iterations
#
A:=Matrix([[1,-x1,-x2],[0,1,-x3],[0,0,1]]);
b:= Vector([1,0,0]);
v := IterativeApproximate(LinearAlgebra:-Transpose(A), b, initialapprox = Vector([1, 3/4, 3/4]), tolerance = 10^(-3), maxiterations = 20, stoppingcriterion = relative(infinity), method = gaussseidel);
mu:=array(1..n,[2.0,1.0,1.0]);
nq:=array(1..M,[0,0,0]);# must initialize queue lengths
for i from 1 to N do

pop:=i;
for j from 1 to M do # mean waiting times
T[j]:=t[j]*(1 + nq[j]) od;
Sum := 0.0;
for j from 1 to M do # mean cycle time
Sum := Sum + v[j]*T[j] od;
for j from 1 to M do #compute the throughputs
lambda[j] := (v[j]*pop)/Sum od;
for j from 1 to M do #compute the queue lengths
nq[j]:= lambda[j]*T[j] od;
for j from 1 to M do #compute the utilizations
u[j]:= lambda[j]*t[j] od;
od;
RETURN(lambda[1]);
end proc;


proc(x1, x2, x3) ... end;

 

sol := Optimization:-NLPSolve(f, {}, {proc (x1, x2, x3) options operator, arrow; x1+x2+x3-5/3 end proc}, 0 .. 1, 0 .. 1, 0 .. 1, initialpoint = [.75, .25, .6667], assume = nonnegative); 1;


Error, (in Optimization:-NLPSolve) non-numeric result encountered

 

I am not sure why I get the error message

 

 

I am trying to solve a matrix system to find the relative arrival rates of a queueing network using Gauss-Seidel.The maple commands are below:

restart;
with(Student[NumericalAnalysis]); with(LinearAlgebra);

A := Matrix([[1, -.333, -.333, -.333], [0, 1, -.333, -.333], [0, -.333, 1, -.333], [0, -.333, -.333, 1]]);

IsDefinite(A, 'query' = 'positive_semidefinite');

true

b := Vector([1, 1, 1, 1]);


IterativeApproximate(A, initialapprox = Vector([1, 1, 1, 1]), tolerance = 10^(-3), maxiterations = 20, stoppingcriterion = relative(infinity), method = gaussseidel);


Error, (in Student:-NumericalAnalysis:-IterativeApproximate) check that the augmented matrix has the correct dimensions

I do not understand this error as the matrix is 4x4 as shown. Can anyone see where I went wrong?

 

Hi, I am new to maple, but I think that my question should be simple.

I have a matrix where each element is an expression. I want to compute the matrix for different constant and to save it without crushing the previous matrix. 

If the file that I joined, I have a first part where the constant are defined. In the second part the expression of the matrix is defined. Finally, I compute each matrix with different constant. Each results is called C_p0, C_s0, C_g0. When I called them back, only the last matrix computed remains.

I would like to be able to save each matrix to performed operation on them later.

Thank you. 

 

Forum_Question1.mw

Homogénéisation

 

restart; with(plots); with(DifferentialGeometry); with(LinearAlgebra); with(Physics)

  NULL

Paramètre des matériaux

 

p[p] := [34.68, 34.82]:
NULL

 

NULLNULL

Tenseurs Élémentaires

 

NULL

Tenseur de rigidité

 

V := 1/((1+upsilon[23])*(-2*upsilon[12]*upsilon[21]-upsilon[23]+1)); G[12] := E/(2*(1+upsilon[12])); C[11] := (-upsilon[23]^2+1)*V*E[1]; C[22] := (-upsilon[12]*upsilon[21]+1)*V*E[2]; C[12] := upsilon[21]*(1+upsilon[23])*V*E[2]; C[23] := (upsilon[12]*upsilon[21]+upsilon[23])*V*E[2]; C[44] := (1/2)*(-2*upsilon[12]*upsilon[21]-upsilon[23]+1)*V*E[2]; C[55] := E[6]; C[33] := C[22]; C[13] := C[12]; C[66] := C[55]; C[21] := C[12]; C[32] := C[23]; C[iso] := Matrix(6, 6, {(1, 1) = C[11], (1, 2) = C[12], (1, 3) = C[12], (1, 4) = 0, (1, 5) = 0, (1, 6) = 0, (2, 1) = C[21], (2, 2) = C[22], (2, 3) = C[23], (2, 4) = 0, (2, 5) = 0, (2, 6) = 0, (3, 1) = C[21], (3, 2) = C[32], (3, 3) = C[22], (3, 4) = 0, (3, 5) = 0, (3, 6) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 0, (4, 4) = C[44], (4, 5) = 0, (4, 6) = 0, (5, 1) = 0, (5, 2) = 0, (5, 3) = 0, (5, 4) = 0, (5, 5) = C[66], (5, 6) = 0, (6, 1) = 0, (6, 2) = 0, (6, 3) = 0, (6, 4) = 0, (6, 5) = 0, (6, 6) = C[66]})

Matrice de rigidité

 

upsilon[23] := upsilon[p]:

Matrix([[C[11], C[12], C[12], 0, 0, 0], [C[21], C[22], C[23], 0, 0, 0], [C[21], C[32], C[22], 0, 0, 0], [0, 0, 0, C[44], 0, 0], [0, 0, 0, 0, C[66], 0], [0, 0, 0, 0, 0, C[66]]])

(1.2.1.1.1)

upsilon[23] := upsilon[s]:

Matrix([[C[11], C[12], C[12], 0, 0, 0], [C[21], C[22], C[23], 0, 0, 0], [C[21], C[32], C[22], 0, 0, 0], [0, 0, 0, C[44], 0, 0], [0, 0, 0, 0, C[66], 0], [0, 0, 0, 0, 0, C[66]]])

(1.2.1.1.2)

upsilon[23] := upsilon[g]:

Matrix([[C[11], C[12], C[12], 0, 0, 0], [C[21], C[22], C[23], 0, 0, 0], [C[21], C[32], C[22], 0, 0, 0], [0, 0, 0, C[44], 0, 0], [0, 0, 0, 0, C[66], 0], [0, 0, 0, 0, 0, C[66]]])

(1.2.1.1.3)

``

C[p0];

Matrix([[C[11], C[12], C[12], 0, 0, 0], [C[21], C[22], C[23], 0, 0, 0], [C[21], C[32], C[22], 0, 0, 0], [0, 0, 0, C[44], 0, 0], [0, 0, 0, 0, C[66], 0], [0, 0, 0, 0, 0, C[66]]])

(1)

``

 

Hello everybody,

* The following set of instructions returns me an error

restart:
with(Maplets[Examples]):
A := Matrix(2,2,[1,2,3,4]):
LinearAlgebra:-Transpose(A);

Error, Transpose is not a command in the Maplets:-Examples:-LinearAlgebra package

(it would be the same for any other command from the LinearAlgebra package)


* If I try 

restart:
with(Maplets[Examples]):
with(LinearAlgebra):
A := Matrix(2,2,[1,2,3,4]):
Transpose(A);

the answer is Transpose(...),  as if Transpose was an undefined function (no matter the order of the loading of the two packages)


* In Maplets[Examples] there is a subpackage named LinearAlgebra : could it be the reason of these observed behaviour ?
* Is there any way to fix that other than copying from Maplets[Examples] the only pieces of code I need avoiding thus its complete loading ?
* More generally : is it possible to load a package "partly" by discarding some of its subpackages ?

Thank you for your answers

Hi all,

Let $A$ be a 0-1 square matrix of order $n$. I want to obtain a matrix $D$ from powers $A$, $A^2$, $\dots$, $A^{n-1}$, where the ($i,j$)-element of $D$ is the smallest $k$ for which the ($i,j$)-element of $A^k$ is nonzero. I only consider the non-diagonal elements of $D$.For example, if the matrix $A$ is Matrix( [[0, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0]]), then $D$ shoule be Matrix([[0, 1, 2, 3, 4], [1, 0, 1, 2, 3], [2, 1, 0, 1, 2], [3, 2, 1, 0, 1], [4, 3, 2, 1, 0]]). However, I cannot obtain this result.

The code is as follows.

p := proc ()

   local A, B, D, m, n, k, r;

   A := Matrix([[0, 1, 0, 0, 0], [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1], [0, 0, 0, 1, 0]]);

   r := LinearAlgebra:-RowDimension(A);

   D := A;

   for k from 2 by 1 to r-1 do

       B := A^k;

       for m from 1 by 1 to r do

           for n from 1 by 1 to r do

               if m <> n and B[m, n] <> 0 and D[m, n] = 0 then

                    D[m, n] := k

                end if;

           end do;

        end do;

   end do;

   D;

end proc;

By executing this procedure, I obtain D=Matrix([[0,1,2,3,3],[1,0,1,2,3],[2,1,0,1,2],[3,2,1,0,1],[3,3,2,1,0]]), which is not I want.

Thanks.

Hi, here is the code I used to try to generate all invertible 4x4 matrices over the finite field F_2 = {0.1}. However, when I look at the elements of GROUP (see below) all the elements are 4x4 matrices with a 2 in each entry. I don't know why this is?

Also, I need help converting all of the invertible 4x4 matrices in the following way: I want the 4x4 matrices to each be written as a string of length 16 with no spaces, commas or brackets. So for example the matrix

a b c d

e f g h

i j k l

m n o p

becomes abcdefghijklmnop

restart:
with(LinearAlgebra):
PRIME := 2;
2

# the group of invertible 4 x 4 matrices over the field F_p

GROUP := []:
M := Matrix([[a,b,c,d],[x,f,g,h],[y,j,k,l],[m,n,o,p]]):
for a from 0 to PRIME-1 do
for b from 0 to PRIME-1 do
for c from 0 to PRIME-1 do
for d from 0 to PRIME-1 do
for x from 0 to PRIME-1 do
for f from 0 to PRIME-1 do
for g from 0 to PRIME-1 do
for h from 0 to PRIME-1 do
for y from 0 to PRIME-1 do
for j from 0 to PRIME-1 do
for k from 0 to PRIME-1 do
for l from 0 to PRIME-1 do
for m from 0 to PRIME-1 do
for n from 0 to PRIME-1 do
for o from 0 to PRIME-1 do
for p from 0 to PRIME-1 do
if Determinant(M) mod PRIME <> 0 then
GROUP := [ op(GROUP), M ]
fi
od od od od od od od od od od od od od od od od:


nops(GROUP);
20160

GROUP;

Dear all;

I need your help to solve the non-square system of equation

 


restart;
with(LinearAlgebra);
 l1 := [1, 1, 1, 0, 0, 0, 0, 0, 0];

l2 := [0, 0, 0, 1, 1, 1, 0, 0, 0];

l3 := [0, 0, 0, 0, 0, 0, 1, 1, 1];

l4 := [1, 0, 0, 1, 0, 0, 1, 0, 0];

l5 := [0, 1, 0, 0, 1, 0, 0, 1, 0];

l6 := [0, 0, 1, 0, 0, 1, 0, 0, 1];

l7 := [0, 0, 1, 0, 1, 0, 1, 0, 0];

A := Matrix([l1, l2, l3, l4, l5, l6, l7]);
    # Unknown vector                    

m := [m1, m2, m3, m4, m5, m6, m7, m8, m9];
# Right hand side                  

 b = [15, 15, 15, 15, 15, 15, 15];

 

# Let the matrix equation : A m =b

1)I need your help to compute the kernel and general solution of this matrix equation

2) can we find a solution if m_k in { 2 3 4 5 6 7 8 } and each of these number appears at least once

3) If there a solution if we consider m_k in the set {0 1 2 3 4 5 6 7 8 }  and the number used exactly one

 

 

Thank you very much for your help

 

 


                     

Hello,

In my code, I need to use 2 packages :
- with(LinearAlgebra)
- with(ListTools)

Problem :
It seems that the package with(ListTools) creates some troubles/ conflicts when I use some functions of the LinearAlgebra package such as DotProduct.

Here a small example to illustrate my issue

with(LinearAlgebra):
with(Student[MultivariateCalculus]):
with(plots):
with(MathML):
DotProduct(<0,0,l>, <0,0,l>, conjugate = false);

--> This code works

with(LinearAlgebra):
with(Student[MultivariateCalculus]):
with(plots):
with(MathML):
with(ListTools):
DotProduct(<0,0,l>, <0,0,l>, conjugate = false);

--> This code doesn't work

I try to replace the line with the DotProduct by the following line but it still doesn't work

with(LinearAlgebra):-DotProduct(<0,0,l>, <0,0,l>, conjugate = false));

 

How can I do to use in my code both packages (LinearAlgebra and ListTools) ?

Thanks a lot for your help

for the questions below

you can use A,B,C as single varible or matrix form if needed

you can use A,B,C as single varible or matrix form if needed

 

1.how to calculate AA1, AA2 and B2 in terms of A,B,C?

2.how to calculate A,B,C in terms of AA1, AA2 and B2 ?

xrestart;

with(LinearAlgebra):
A := Matrix([[a1,a2,a3],[a4,a5,a6],[a7,a8,a9]]);
B := Matrix([[b1,b2,b3],[b4,b5,b6],[b7,b8,b9]]);
C := Matrix([[c1,c2,c3],[c4,c5,c6],[c7,c8,c9]]);
#AA1,AA2, C:=seq(Matrix(3, symbol=i), i=[a,b,c]);
#AA1 := Matrix([[aaa1,0,0],[0,aaa1,0],[0,0,aaa1]]);
#AA2 := Matrix([[aab1,0,0],[0,aab1,0],[0,0,aab1]]);
#B2 := Matrix([[aabb1,0,0],[0,aabb1,0],[0,0,aabb1]]);
AA1 := Matrix([[aaa1,aaa2,aaa3],[aaa4,aaa5,aaa6],[aaa7,aaa8,aaa9]]);
AA2 := Matrix([[aab1,aab2,aab3],[aab4,aab5,aab6],[aab7,aab8,aab9]]);
B2 := Matrix([[aabb1,aabb2,aabb3],[aabb4,aabb5,aabb6],[aabb7,aabb8,aabb9]]);
eq2 := C.A+C.B;
eq3 := C.B+C;
eq4 := B+C.A;
ABC := fsolve(map(t->Equate(op(t))[], [eq2=AA1,eq3=AA2,eq4=B2]));

Suppose we are given a matrix M[n*2n] of n linearly independent row vectors. Then I am trying to create a procedure to add n more linearly independent row vectors to this matix resulting in to a matrix M[2n*2n].

Consider this easy example, if the given matrix $M_{2*4}$ is

Matrix(2, 4, {(1, 1) = 4, (1, 2) = 1, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 4, (2, 4) = 1}) 
then we can add $[0,0,0,1]$ and $[0,0,1,0]$ to obtain the matrix $M_{4*4}$

Matrix(4, 4, {(1, 1) = 4, (1, 2) = 1, (1, 3) = 0, (1, 4) = 0, (2, 1) = 0, (2, 2) = 0, (2, 3) = 4, (2, 4) = 1, (3, 1) = 1, (3, 2) = 0, (3, 3) = 0, (3, 4) = 0, (4, 1) = 0, (4, 2) = 0, (4, 3) = 1, (4, 4) = 0})

 

Can I use rref form?Thank you for your help.

 

 

a := Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})with(LinearAlgebra)

 

a.a^T = (Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4})).(Matrix(2, 2, {(1, 1) = 1, (1, 2) = 2, (2, 1) = 3, (2, 2) = 4}))^TNULL

I am not getting the answer.

I want to get the answer for this product of matrix and its tranport.

I do not want to create transport matrix again for this calculation.

The transporse matrix b is

b := Matrix(2, 2, {(1, 1) = 1, (1, 2) = 3, (2, 1) = 2, (2, 2) = 4}) = Matrix([[1, 3], [2, 4]])

a.a^T is equal to a.b = Matrix([[5, 11], [11, 25]])NULL

For large matrices i cannot do this. Hence this request.Any one please send the code. Thanks.

 

Download transpose_doubt_1.mwtranspose_doubt_1.mw

Ramakrishnan V

rukmini_ramki@hotmail.com

I have a multivariate polynomial in x and y. How can I firstly collect the terms with respect to the powers of x and y and then simplifying their coefficients.

restart

with(RealDomain):

with(LinearAlgebra):

A := Matrix(5, 5, {(1, 1) = 0, (1, 2) = 1, (1, 3) = 1, (1, 4) = 1, (1, 5) = 1, (2, 1) = 1, (2, 2) = 0, (2, 3) = c__1, (2, 4) = y, (2, 5) = c__2, (3, 1) = 1, (3, 2) = c__1, (3, 3) = 0, (3, 4) = c__3, (3, 5) = x, (4, 1) = 1, (4, 2) = y, (4, 3) = c__3, (4, 4) = 0, (4, 5) = c__4, (5, 1) = 1, (5, 2) = c__2, (5, 3) = x, (5, 4) = c__4, (5, 5) = 0})

Matrix(%id = 4510803138)

(1)

B := Determinant(A)

-2*c__1^2*c__4+2*c__1*c__2*c__3+2*c__1*c__2*c__4-2*c__1*c__2*x+2*c__1*c__3*c__4-2*c__1*c__3*y-2*c__1*c__4^2+2*c__1*c__4*x+2*c__1*c__4*y+2*c__1*x*y-2*c__2^2*c__3-2*c__2*c__3^2+2*c__2*c__3*c__4+2*c__2*c__3*x+2*c__2*c__3*y-2*c__2*c__4*y+2*c__2*x*y-2*c__3*c__4*x+2*c__3*x*y+2*c__4*x*y-2*x^2*y-2*x*y^2

(2)

``

 

Download A.mw

1 2 3 4 5 6 7 Page 1 of 7