Items tagged with linearalgebra

First Question: How to define nx1 matrix Y:=(y1,y2,...,yn) ? (n is a Natural number while it is ungiven)

Second Question: How to derivative of matrix Y with respect to nx1 matrix X:=(x1,x2,...,xn) ?


My efforts for the first question:  (I know to define 6x1 matrix etc. , but I dont know to define nx1 matrix

restart: Matrix(1..6,1,symbol=y) 


My efforts for the second question:

restart; with(VectorCalculus);
Matrix([x^2, x*y, x*z]);
Jacobian([x^2, x*y, x*z], [x, y, z]);

Can you help me? 


Let matrix A be nxn matrix. How to find modal matrix M, the modal matrix for the matrix A is the n × n matrix formed with the eigenvectors of A as columns in M? (D=M^-1*A*M, where D is dioganal matrix with the eigenvalues of A on the main diagonal of D)

For example;

A := Matrix(2, 2, [-4, -2, 3, 1])

How to find M modal matrix?


I attempted to use convolution in AudioTools to convolve 2 vectors with arbitrary values, but could not since the operation is expecting numeric values.  Can this be done?    Is there not a convolution operastor in the LinearAlgebra package?  See attached:


Hello guys, i have some matrix equations.

A^(T)*X+X*A+Q = 0 , where A,Q - matrixs, X - unknown matrix, i need to solve this.

i tried to solve this from methods, but not successfully.

How can to solve this problem?


Dear readers,

For a question for my students I want them to calculate tge resulting vector from two vectors. The student had to answer by giving the length and angle of the resulting vector.

For the question the vector angle is always larger as 180 derges, the student should for example give a result of 270 degrees.

Currently I'm using the following code:


As you can see maple will always give an angle smaller than 180 degrees since the angle between two vectors is always 180 degrees or smaller.

Can anyone tell me how I should code this problem such that the rest for A4 will be 270 degrees rather than 90 degrees, as is given from the current way of coding.

Thank you in advance.

Students using Maple often have different needs than non-students. Students need more than just a final answer; they are looking to gain an understanding of the mathematical concepts behind the problems they are asked to solve and to learn how to solve problems. They need an environment that allows them to explore the concepts and break problems down into smaller steps.

The Student packages in Maple offer focused learning environments in which students can explore and reinforce fundamental concepts for courses in Precalculus, Calculus, Linear Algebra, Statistics, and more. For example, Maple includes step-by-step tutors that allow students to practice integration, differentiation, the finding of limits, and more. The Integration Tutor, shown below, lets a student evaluate an integral by selecting an applicable rule at each step. Maple will also offer hints or show the next step, if asked.  The tutor doesn't only demonstrate how to obtain the result, but is designed for practicing and learning.

For this blog post, I’d like to focus in on an area of great interest to students: showing step-by-step solutions for a variety of problems in Maple.

Several commands in the Student packages can show solution steps as either output or inline in an interactive pop-up window. The first few examples return the solution steps as output.

Precalculus problems:

The Student:-Basics sub-package provides a collection of commands to help students and teachers explore fundamental mathematical concepts that are core to many disciplines. It features two commands, both of which return step-by-step solutions as output.

The ExpandSteps command accepts a product of polynomials and displays the steps required to expand the expression:

ExpandSteps( (a^2-1)/(a/3+1/3) );

The LinearSolveSteps command accepts an equation in one variable and displays the steps required to solve for that variable.

LinearSolveSteps( (x+1)/y = 4*y^2 + 3*x, x );

This command also accepts some nonlinear equations that can be reduced down to linear equations.

Calculus problems:

The Student:-Calculus1 sub-package is designed to cover the basic material of a standard first course in single-variable calculus. Several commands in this package provide interactive tutors where you can step through computations and step-by-step solutions can be returned as standard worksheet output.

Tools like the integration, differentiation, and limit method tutors are interactive interfaces that allow for exploration. For example, similar to the integration-methods tutor above, the differentiation-methods tutor lets a student obtain a derivative by selecting the appropriate rule that applies at each step or by requesting a complete solution all at once. When done, pressing “Close” prints out to the Maple worksheet an annotated solution containing all of the steps.

For example, try entering the following into Maple:


Next, right click on the Matrix and choose “Student Calculus1 -> Tutors -> Differentiation Methods…

The Student:-Calculus1 sub-package is not alone in offering this kind of step-by-step solution finding. Other commands in other Student packages are also capable of returning solutions.

Linear Algebra Problems:

The Student:-LinearAlgebra sub-package is designed to cover the basic material of a standard first course in linear algebra. This sub-package features similar tutors to those found in the Calculus1 sub-package. Commands such as the Gaussian EliminationGauss-Jordan Elimination, Matrix Inverse, Eigenvalues or Eigenvectors tutors show step-by-step solutions for linear algebra problems in interactive pop-up tutor windows. Of these tutors, a personal favourite has to be the Gauss-Jordan Elimination tutor, which were I still a student, would have saved me a lot of time and effort searching for simple arithmetic errors while row-reducing matrices.

For example, try entering the following into Maple:


Next, right click on the Matrix and choose “Student Linear Algebra -> Tutors -> Gauss-Jordan Elimination Tutor

This tutor makes it possible to step through row-reducing a matrix by using the controls on the right side of the pop-up window. If you are unsure where to go next, the “Next Step” button can be used to move forward one-step. Pressing “All Steps” returns all of the steps required to row reduce this matrix.

When this tutor is closed, it does not return results to the Maple worksheet, however it is still possible to use the Maple interface to step through performing elementary row operations and to capture the output in the Maple worksheet. By loading the Student:-LinearAlgebra package, you can simply use the right-click context menu to apply elementary row operations to a Matrix in order to step through the operations, capturing all of your steps along the way!

An interactive application for showing steps for some problems:

While working on this blog post, it struck me that we did not have any online interactive applications that could show solution steps, so using the commands that I’ve discussed above, I authored an application that can expand, solve linear problems, integrate, differentiate, or find limits. You can interact with this application here, but note that this application is a work in progress, so feel free to email me (maplepm (at) any strange bugs that you may encounter with it.

More detail on each of these commands can be found in Maple’s help pages.


Please help me solve this question using maple (need the steps in solving).

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.





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})



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





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.


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

NLPSolve, QPSolve]
global T,lambda,nq,u;
local i,j,pop,Sum;
# Gauss-Seidel iterations
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);
nq:=array(1..M,[0,0,0]);# must initialize queue lengths
for i from 1 to N do

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;
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:

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');


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.



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


Paramètre des matériaux


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



Tenseurs Élémentaires



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]]])


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]]])


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]]])




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]]])




Hello everybody,

* The following set of instructions returns me an error

A := Matrix(2,2,[1,2,3,4]):

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 

A := Matrix(2,2,[1,2,3,4]):

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;


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.


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

PRIME := 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 ]
od od od od od od od od od od od od od od od od:



1 2 3 4 5 6 7 Page 1 of 7