Items tagged with matrix



I am using codegen to generate code from Maple expressions. More specifically I want to export non quadratic matix. The export works for matrices that have more columns than rows, but not for matrices with more rows than columns. There I receive the error:

Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2

A workaround would be to transpose the matrix before the export, and to transpose on the import (in Matlab) but I don't want to overcomplicate my code. Thanks for your help!

I have attached a demonstration worksheet below.


## test codegen non quadratic returnarray

## works
#Myfun := Matrix(3,3)

## works
#Myfun := Matrix(2,3):Myfun(2,3):= 3*b;

## does not work
Myfun := Matrix(3,2):Myfun(3,2):= 3*b;

Myfun := Matrix(3, 2, {(1, 1) = 0, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})


Myfun(1):= 7*a;

Myfun := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})


## codegen works best with arraybased matrices, and call by reference becomes possible

returnArray:= convert(Myfun,matrix)

returnArray := Matrix(3, 2, {(1, 1) = 7*a, (1, 2) = 0, (2, 1) = 0, (2, 2) = 0, (3, 1) = 0, (3, 2) = 3*b})



Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2



Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2



Error, (in codegen/array/entry) 2nd index, 3, larger than upper array bound 2






How to write a code find fundamental matrix of the following Matrix?

restart; with(LinearAlgebra): A:=Matrix([[0, 1, 0, 0], [-a, 0, b, 0], [0, 0, 0, 1], [c, 0, -d, 0]]);eigenvectors(A);

where a,b,c,d∈IR.

I want to find eigenvalues and eigenvectors and then want to calculate e^( λ i)*ri  where λi's are eigenvalues, ri's are eigenvectors of A for i=1,2,3,4  respectively.

Then, I want to calculate Wronskian of the matrix which consists of vectors e^(λi)*ri in the columns. Could you help me?

See: Fundamental Matrix


i have a vector-valued function mapping from R^n  -> R^m
I  compute its Jacobian Matrix as well as the Hessian Matrix of each output with regard to the inputs, which works so far.
Now I would like to use the CodeGeneration package to generate optimized C Code to compute these matrices numerically. This is, where i encounter a Problem:

I would like to optimize Code for all matrixes at once, because they contain common subexpressions. However CodeGeneration::C tells me it is unable to optimize the given input and generates unoptimized code.

I appended an exemplary file to illustrate the problem:

short version:

C(Jac, optimize = tryhard, resultname = JacobianMatrix);
C(H1, optimize = tryhard, resultname = Hessian1); 
C(H2, optimize = tryhard, resultname = Hessian2); 
C(H3, optimize = tryhard, resultname = Hessian3)

works, but is suboptimal.

C([JacobianMatrix = Jac, Hessian1 = H1, Hessian2 = H2, Hessian3 = H3], optimize)

fails to optimize and

C([Jac, H1, H2, H3], optimize)

fails completely.

(With Jac beeing a m by n matrix and H1-3 beeing n by n matrices)

If anyone can tell me what I'm missing here I'd really appreciate the help.

I know that is easy for you but i am new in this topics.I want to write a code to generate a matrix which have entries consist of matrices(it has differnt dimensions)

I need to create a list of matrices.

for b from 1 to 12 by 5 do
if i=b+P[a] and j=b+P[a] then E[a]
elif i=b+P[a] and j=b+N+2+P[a] then -E[a]
elif i=b+P[a]+N+2 and j=b+P[a] then -E[a]
elif i=b+P[a]+N+2 and j=b+P[a]+N+2 then E[a]
else 0:
end if:
B[b]:=add(i,i=[seq(Matrix(20,B), a=1..3)]);
end do;

It isn't indexing the first and second variable, only the last one was indexed. 

I wrote some procedures in an older version of Maple to sort through a matrix and find repeated elements, and then set the matrix elements equal to one another. As an example, consider the matrix:

Matrix(4, 4, {(1, 1) = 31774769/38880000, (1, 2) = -90858559/233280000, (1, 3) = -76547233/69984000, (1, 4) = -119275567/139968000, (2, 1) = -90858559/233280000, (2, 2) = 1506841/6480000, (2, 3) = 442249/720000, (2, 4) = 85514221/116640000, (3, 1) = -76547233/69984000, (3, 2) = 442249/720000, (3, 3) = 592249771/349920000, (3, 4) = 121562339/87480000, (4, 1) = -119275567/139968000, (4, 2) = 85514221/116640000, (4, 3) = 121562339/87480000, (4, 4) = 170546323/87480000}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])
Due to its symmetric nature the upper triangular matrix is just the same as the lower triangular. i.e. the elements are equal: (2,1)=(1,2), (3,1)=(1,3) etc...

I have attached a minimal working example Maple script, which processes an input matrix, finds repeats and sets the elements equal to one another (e.g. [1,2]=[2,1], literally printing this) and saves the output to a file using a specific format for processing by another program. The matrix in the file is numeric but the actual matrices contain a lot of algebraic terms and can get quite large. This is where my procedures struggle as they take a very, very long time to process larger algebraic matrices to group the repeats. Is there a more Maple friendly way of going about this problem rather than these "archaic" procedures?

Here is the script:

Thank you in advance


How do I assume variables as  Matrixs for calculation?
Please help me to solve this problem :


A := M12*M21+M11;
                         M12 M21 + M11
solve(A = 0, M12);
Warning, solve may be ignoring assumptions on the input variables.
                             - ---
solve(A = 0, M12, useassumptions = true);
                             - ---

How can I get solution being a matrix?
Thank you very much !!!

I have a Maple code which generates a matrix, saves it to a .txt file and this is then read in to a C++ program. I have hit a snag with these matrices, in that they are generating absolutely enourmous .txt files. I need to get to a 5000*5000 matrix yet a 200*200 is generating a 100MB file.

The matrix elements contain a lot of algebraic terms which I would like to keep general as these are defined in the C++ code. They also contain hypergeometric functions which in the example below I have left unsimplified (although they are simplified before reaching C++). I have tried various operations/combinations to simplify, but the file sizes still come out very large.

From previous experience expanding the expressions and then simplifying allows Maple to "do more" with it, but it does not seem to work in this instance. I have tried map(options,expr), simplify(expr,options), combine(expr,options), convert (expr,options) etc... The script attached only contains a small example 10*10 matrix on its own without the code which generates it due to the size of the code. What is the best way to simplify these matrices to generate the smallest .txt file?

Any help is appreciated.



I have a question and I hope someone will be able to answer it.

I would like to create a matrix of functions depending on the number of the line or the arrow. I think the best is to show with a very basic example:

I have the following program



for i from 1 to n do: R(1,i):=x->i*x:end do:

So, I have a matrix, one row, n columns. At the ith column, I want to have the function f(x)=i*x.

Unfortutanely, with my program, I obtain for example for the first column the function f(x)=11*x. At the second column, I get the same result. It seems that I can define matrices of functions but it is impossible in the definition of the function to use the number of the column. Do you have any idea about how to write a program?

Any help would be very appreciated. 




To check my arguments in a procedure I need something like

myproc := proc(M :: Matrix(square, rational)

                       , N :: Matrix(shape=triangular[lower, unit], datatype = rational
                       , O :: Matrix(shape = square, dimension = 5


end proc;

How does that work in Maple? What is the correct Syntax? I tried many different things that doesn't fit.

I am trying to use a do loop with if/else statements to create a 5x5 unit matrix. I made an empty array. Converted it to a matrix. Then made a do loop where I was trying to get the matrix elements where i=j to be 1 and all else to be 0. It didn't spit out a matrix.

Any advice? I assume I must have missed a small detail in syntax.




U := array(1 .. 5, 1 .. 5);

array( 1 .. 5, 1 .. 5, [ ] )



for i to 5 do for j to 5 do if i = j then U[i, j] := 1 else U[i, j] := 0 end if end do end do







By the way, I am open to completely different methods, also! I was just trying to use loops to do it rather than inbuilt commands.

Pay attention to the Next Question


I have to find which column of a matrix contains repeated elements, i have done it in this but i'm afraid that the nested loops don't run correctly:

for j by 1 to 10 do 
for i by 1 to 30 do 
	for x by 1 to 30 do
		if Dati[x,j] = h then
			if x <> i then
				return j;
				end if;
				end if;
				end do;
				 end do;
				  end do;


How can i convert each column of a matrix(30X10) in a list?

Hi everybody

In the attached file, when I run the code an error appears while calculating "omegaL1" parameter. The dimensions of the matrices are correct but the source of error is unknown to me. Can anyone help me?

Thanks in advance 

1 2 3 4 5 6 7 Last Page 1 of 41