## Problem with codegen applied to a rectangular (Arr...

Hey,

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;
 (1)
 > Myfun(1):= 7*a;
 (2)
 > ## codegen works best with arraybased matrices, and call by reference becomes possible
 > returnArray:= convert(Myfun,matrix)
 (3)
 > codegen[makeproc](Myfun,[a,b])
 > codegen[makeproc](returnArray,[returnArray,a,b])
 > codegen[makeproc](returnArray,[a,b])
 >

## Eigenvalues , eigenvectors and Fundamental Matrix...

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?

## How to generate optimized Code for multiple Matric...

Hello,

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: Jacobian_Hessian_codeGeneration_tryout.mw

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.

## Matrix which have matrix entry...

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)

## Creating a list of Matrices...

I need to create a list of matrices.

with(LinearAlgebra):
interface(rtablesize=50);
E:=[E1,E2,E3]:
P:=[0,1,2]:
N:=3:
B:=[1,2,3]:
for b from 1 to 12 by 5 do
B:=(i,j)->
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:
end do;
H:=[seq(B[b],b=1..12,5)];

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

## Quick way to find duplicates in a matrix and set t...

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:

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:

duplicates_matrix_.mw

-Yeti

How do I assume variables as  Matrixs for calculation?

assume(M11::Matrix);
assume(M12::Matrix);
assume(M21::Matrix);
assume(M22::Matrix);
assume(A::Matrix);

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

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

## Simplifying very large matrix elements...

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?

Large_Matrix.mw

Any help is appreciated.

-Yeti

## How to define a matrix of functions depending on t...

Dears,

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

n:=4:

R:=Matrix(1,n):

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.

## Check Matrix argument when entering a procedure...

Hello,

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.

## Using if/else statements to fill an empty matrix?...

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.

 (1)

 (2)

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.

## How to find a linear parameter within a matrix by ...

Pay attention to the Next Question

## Nested loops and matrix...

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
h:=Dati[i,j];
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;```

## Matrix and lists...

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