## Items tagged with matrix

Dear All

I want to use subs command to replace products in expression with entries from matrix. When I use "subs" command it returns same result as original without any substitution. But when I use "algsubs", it works fine, but is complicated to apply if there are large number of substitutions.

 >
 (1)
 >
 (2)
 >
 (3)
 >
 (4)

Why this command subs in not replacing  products   from matrix (1)?????

 >
 (5)

It worked !!!! But If I try "algsubs" like :

 >

See it is giving error !!! but still I can use "algsubs" as follow:

 >
 (6)

But this procedure is complex, I want to use "subs" only. I know it complexity of terms in (3) might me creating problem.

 >
 (7)
 >

Regards

## Sparse Matrix Products in Maple

by: Maple

I thought I would share some code for computing sparse matrix products in Maple.  For floating point matrices this is done quickly, but for algebraic datatypes there is a performance problem with the builtin routines, as noted in http://www.mapleprimes.com/questions/205739-How-Do-I-Improve-The-Performance-Of

The code is fairly straightforward in that it uses op(1,A) to extract the dimensions and op(2,A) to extract the non-zero elements of a Matrix or Vector, and then loops over those elements.  I included a sparse map function for cases where you want to map a function (like expand) over non-zero elements only.

# sparse matrix vector productspmv := proc(A::Matrix,V::Vector)local m,n,Ae,Ve,Vi,R,e;  n, m := op(1,A);  if op(1,V) <> m then error "incompatible dimensions"; end if;  Ae := op(2,A);  Ve := op(2,V);  Vi := map2(op,1,Ve);  R := Vector(n, storage=sparse);  for e in Ae do    n, m := op(1,e);    if member(m, Vi) then R[n] := R[n] + A[n,m]*V[m]; end if;  end do;  return R;end proc:
# sparse matrix productspmm := proc(A::Matrix, B::Matrix)local m,n,Ae,Be,Bi,R,l,e,i;  n, m := op(1,A);  i, l := op(1,B);  if i <> m then error "incompatible dimensions"; end if;  Ae := op(2,A);  Be := op(2,B);  R := Matrix(n,l,storage=sparse);  for i from 1 to l do    Bi, Be := selectremove(type, Be, (anything,i)=anything);    Bi := map2(op,[1,1],Bi);    for e in Ae do      n, m := op(1,e);      if member(m, Bi) then R[n,i] := R[n,i] + A[n,m]*B[m,i]; end if;    end do;  end do;  return R;end proc:
# sparse mapsmap := proc(f, A::{Matrix,Vector})local B, Ae, e;  if A::Vector then    B := Vector(op(1,A),storage=sparse):  else    B := Matrix(op(1,A),storage=sparse):  end if;  Ae := op(2,A);  for e in Ae do    B[op(1,e)] := f(op(2,e),args[3..nargs]);  end do;  return B;end proc:

As for how it performs, here is a demo inspired by the original post.

n := 674;k := 6;
A := Matrix(n,n,storage=sparse):for i to n do  for j to k do    A[i,irem(rand(),n)+1] := randpoly(x):  end do:end do:
V := Vector(n):for i to k do  V[irem(rand(),n)+1] := randpoly(x):end do:
C := CodeTools:-Usage( spmv(A,V) ):  # 7ms, 25x fasterCodeTools:-Usage( A.V ):  # 174 ms
B := Matrix(n,n,storage=sparse):for i to n do  for j to k do    B[i,irem(rand(),n)+1] := randpoly(x):  end do:end do:
C := CodeTools:-Usage( spmm(A,B) ):  # 2.74 sec, 50x fasterCodeTools:-Usage( A.B ):  # 2.44 min
# expand and collect like termsC := CodeTools:-Usage( smap(expand, C) ):

## Determinant of coefficient matrix...

I want to set the determinant of the coefficient matrix equal to zero and then solving for the roots. But I could not achieve it via Maple. Can you help me please?

You can reach two examples in the following file.  Yeni_Microsoft_Word_Belgesi_(2).docx

Besides. how can i compute the following transcental equations via maple

sinh(beta*L)*sin(beta*L)=0

cosh(beta*L)*cos(beta*L)-1=0

cosh(beta*L)*cos(beta*L)+1=0

regards

mehmet

## Convert ODE system to matrix form...

Sorry for disturbing you. I am wondering if there is an easier approach in Maple that could convert a system of second order differential equations into matrix form. Of course, we could do it by hand easily if the degrees of freedom is small. I would like to know if we could use Maple to do so.

Here is an example with 6 degrees of freedom: the variables are u, v, w, alpha, beta and gamma. And, this is a uncoupled system.

Vector(6, {(1) = 2*R^2*(diff(w(t), t))*Pi*Omega*h*rho+R^2*(diff(u(t), t, t))*Pi*h*rho-R^2*u(t)*Pi*Omega^2*h*rho = 0, (2) = R^2*(diff(v(t), t, t))*Pi*h*rho = 0, (3) = -2*R^2*(diff(u(t), t))*Pi*Omega*h*rho+R^2*(diff(w(t), t, t))*Pi*h*rho-R^2*w(t)*Pi*Omega^2*h*rho = 0, (4) = (1/4)*R^4*Pi*(diff(alpha(t), t, t))*h*rho+(1/12)*R^2*Pi*(diff(alpha(t), t, t))*h^3*rho+(1/6)*R^2*Pi*(diff(gamma(t), t))*Omega*h^3*rho-(1/12)*R^2*Pi*alpha(t)*Omega^2*h^3*rho = 0, (5) = (1/2)*R^4*Pi*(diff(beta(t), t, t))*h*rho-(1/2)*R^4*Pi*beta(t)*Omega^2*h*rho = 0, (6) = (1/4)*R^4*Pi*(diff(gamma(t), t, t))*h*rho+(1/12)*R^2*Pi*(diff(gamma(t), t, t))*h^3*rho-(1/6)*R^2*Pi*(diff(alpha(t), t))*Omega*h^3*rho-(1/12)*R^2*Pi*gamma(t)*Omega^2*h^3*rho = 0});

The objective is to reform it into matrix form : M*diff(X(t), t, t)+C*diff(X(t), t)+K*X(t)=F.

Thank you in advance for taking a look.

## Wrong type inside a loop...

Eight matrices inside the list J:

J := [Matrix([[1, 0], [0, 1]]), Matrix([[0, -I], [-I, 0]]), Matrix([[0, -1], [1, 0]]), Matrix([[-I, 0], [0, I]]), Matrix([[-1, 0], [0, -1]]), Matrix([[0, I], [I, 0]]), Matrix([[0, 1], [-1, 0]]), Matrix([[I, 0], [0, -I]])];

Function member identifies J[2] as a member of J and returns its position in j:

member(J[2], J, 'j'); j;

Matrix multiplication inside a loop does not have a matrix type:

for i to 1 do for j to 2 do a := J[i].J[j]; member(a, J, 'k'); print(i, j, k, a, whattype(a)) end do end do;

Has anyone any ideia of what is going on?

## How to write a special matrix?...

Hello everyone.  Let n be a positive number; I seek how to write the matrix Z\in M_{2^n,n} that is defined as follows:

for every i,j, Z_{ij}\in \{-1,1\}.

When I consider the 2^n rows of Z, I want to find ALL the possible sequences of length n with the entries +-1. A toy example, when n=2, is Z=\begin{pmatrix}1&1\\1&-1\\-1&1\\-1&-1\end{pmatrix}.

## Error, unable to parse 'mverbatim'...

OnesM:=Matrix(%id=119376536)

Anyone can solve this??

Many thanks!

## How to import matrix from MATLAB? ...

Hi guys,
I want to import symbolic matrix from matlab to Maple, How I can do that ?

## Exporting to Excel...

I want to solve a system of equations using f-solve (two unknowns) and exporting the solutions to a matrix where the solutions are in seperate columns. How do I do this?

I have tried:

for i from 1 to 937 do

AP[i,1]:=fsolve(x=KL[i,1].y=KL[i,2],x=..8,y=0..15))

end if

end do

But this returns the solutions for X and Y in the same column. Also, for the values that are not possible to solve, it returns the entire expression instead of e.g. 0 or "undefined".

Thank you.

## How to factorize to matrix ...

from determinant's polynomial?

## Problem with procedure...

I tried to make a procedure that would find the determinant of any 3x3 matrix but I keep getting unterminated procedure what should I change??

Code:
DeterminantMat:=proc(matA::Array)
local  i::integer,  j::integer,  x::integer,  y::integer,  A::integer,  B::integer,  indice::integer,  S::integer:
A:=0:  B:=0:  S:=0: i:= 1:  j:=1:  x:=1:  y := 1:  indice:=1:

for x from 1 to 3 do
indice := 1:
for i  from 1 to  3 do
if x = i then
end do:
else if x <>i then
for j from 1 to 3 do
if y = j then  end do:
else if indice = 1 then  A := matA(i,j):  indice := 2:
else if indice = 2 then  B:=matA(i,j):  indice :=3:
else if indice = 3 then  B :=B * matA(i,j):  indice :=4:
else if indice = 4 then  A := A * matA(i,j):
if x = 2 then  S := S + (-1 * matA(x,y)) * (A-B):
else  S := S + matA(x,y) * (A-B):   end if:   end if:
end do:
end if:
end do:
end do:
end proc:

## Hilbertmatrix and reflectionmatrix...

Hi, I have 2 Questions about programming in maple. I will be thankful if you help me as soon as possible.

First; How can I display a n*n HilbertMatrix?

Second: I wanna make a 2*2 matrix which its transpose is egual to its inverse, How can I do that by helping reflectionmatrix?

(I'm an amateur programmer, I use maple 13 on my pc)

## Eigenvalues of a huge matrix...

I faced a very large eigenproblem during my research. The square matrix under consideration is of size more than 2^30 times 2^30. I have tried to deal with this problem by the QR algorithm with double implicit shift (more precisely, the Francis double step QR algorithm). I'm a very beginner of programming, but I tried as follows:

--------------------------------------------------------------------------------------------------

A := Matrix([[7, 3, 4, -11, -9, -2], [-6, 4, -5, 7, 1, 12], [-1, -9, 2, 2, 9, 1], [-8, 0, -1, 5, 0, 8], [-4, 3, -5, 7, 2, 10], [6, 1, 4, -11, -7, -1]]):
H := HessenbergForm(A):
p:=6:
for p while p>2 do:
q:=p-1:
s:=H(q,q)+H(p,p):
t:=H(q,q)*H(p,p)-H(q,p)*H(p,q):
x:=(H(1,1))^(2)+H(1,2)*H(2,1)-s*H(1,1)+t:
y:=H(2,1)*(H(1,1)+H(2,2)-s):
z:=H(2,1)*H(3,2):
for k from 0 to p-3 do:
V:=Vector([x,y,z]):
P:=Transpose(HouseholderMatrix(1/(Norm(V+exp(argument(V(1))*I)*Norm(V,2)*Vector(3,shape=unit[1]),2))*(V+exp(argument(V(1))*I)*Norm(V,2)*Vector(3,shape=unit[1])))):
r:=max(1,k):
H[k+1..k+3,r..6]:=MatrixMatrixMultiply(Transpose(P),SubMatrix(H,[k+1..k+3],[r..6])):
r:=min(k+4,6):
H[1..r,k+1..k+3]:=MatrixMatrixMultiply(SubMatrix(H,[1..r],[k+1..k+3]),P):
x:=H(k+2,k+1):
y:=H(k+3,k+1):
if k<3 then z:=H(k+4,k+1):
end if:
od:
P:=GivensRotationMatrix(Vector([x,y]),1,2):
H[q..p,p-2..6]:=MatrixMatrixMultiply(Transpose(P),SubMatrix(H,[q..p],[p-2..6])):
H[1..p,p-1,p]:=MatrixMatrixMultiply(SubMatrix(H,[1..p],[p-1,p]),P):
if abs(H(p,q))<10^(-20)*(abs(H(q,q))+abs(H(p,p))) then    H(p,q):=0: p:=p-1:q=p-1:
elif abs(H(p-1,q-1))<10^(-20)*(abs(H(q-1,q-1))+abs(H(q,q))) then    H(p-1,q-1):=0: p:=p-2:q:=p-1:
end if:  od:
--------------------------------------------------------------------------------------------------

It seemed that replacing 0 in a Hessenberg matrix by a non-zero element is not allowed. How can I remedy this?

Plus, can anyone tell me the problem of the above thing(it's not really a programming...;( ), please?

I would also appreciate it if someone let me know a better idea for a huge eigenproblem.

## Serious Maple2015 bug ...

in LinearAlgebra Eigenvectors calculation.

So the above output startled me.  I have used the Maple Linear Algebra Eigenvalues, Eigenvectors commands many times with no problem.  Can any one explain to me what is going on.  The program correctly calculates the eigenvalues for the matrix which are all distinct for a real symmetric matrix, and thus should have three distinct non-zero eigenvectors, yet the eigenvectore command returns only zeros for the eigenvectors.  I calculated an eigenvector by hand corresponding to the eigenvalue of 1 and obtained (1, -sqrt(2)/sqrt(3), -1/sqrt(3).

So this is either a serious bug or I am going completely insane.

## Symbolic matrix calculus in Maple...

Sorry for the uninformative title. I've never used Maple, but I'm willing to buy a student license and learn it. But before spending too much effort and money I need to know if it suits my needs.

Basically what I need to do is:

1) I have a positive definite symmetric matrix of size nxn, where n can range from 2 to inf. I don't know the elements, except the fact that the diagonal has ones everywhere. All I know is that the elements out of the diagonal are in the range [0,1)

2) I have to compute the lower triangular cholesky decomposition of this matrix, lets call it L.

3) I need to subtract from each element of L the mean of the elements in the respective column. Lets call this matrix L*

4) Then I need to evaluate another nxn matrix computed from the elements of L* following a simple pattern.

5) Finally I need to find the eigenvalues of this last matrix.

What I would ideally want is to get a symbolic representation of the n eigenvalues as symbolic functions of the (unknown) elements of the matrix at point 1.

I can drop the assumption of n being unknown, i.e. fix n=3 and get the 3 functions that, after replacing the right values, give me the eigenvalues, then fix n=4 and get 4 functions, etc.

Is this possible to do in maple?

Thank you

 5 6 7 8 9 10 11 Last Page 7 of 46
﻿