# Items tagged with matrixmatrix Tagged Items Feed

### Translate maple code to C code...

March 23 2015
1 0

I want to translate my maple code with matrice multiplication  to C code. But the command  "Multiply" cannot be translated. So I want to edit the function translation by myself. I use "AddFunction" command to create a new function  "Multiply" and want to specify its corresponding C code.

f := proc ()
local x,y;
x := Matrix([[1, 2], [3, 4]]);
y := Matrix([[1,3],[4,2]]);
Multiply(x, y);
NULL;
end proc;

LanguageDefinition:-Define("NewC", extend = "C", AddFunction("Multiply", [Matrix,Matrix]::Matrix,
proc (X, Y)
local a,b;
a := 2;
b := convert(a, string);
Printer:-Print("Mmultiply(", X);
Printer:-Print(",", Y, ")"); Printer:-Print("\n");
Printer:-Print("from", b, "to");
Printer:-Print(",", Y, "do") end proc, numeric = double));
Translate(f, language = "NewC")

But when I run it, the "Multiply" function cannot be translated.  The result is:

Warning, type signature [CodeGeneration:-Names:-ArrayType(integer,CodeGeneration:-Names:-ArrayRanges(1 .. 2,1 .. 2),CodeGeneration:-Names:-ArrayOptions()), CodeGeneration:-Names:-ArrayType(integer,CodeGeneration:-Names:-ArrayRanges(1 .. 2,1 .. 2),CodeGeneration:-Names:-ArrayOptions())] for function Multiply is not recognized
void f (void)
{
int x[2][2];
int y[2][2];
x[0][0] = 1;
x[0][1] = 2;
x[1][0] = 3;
x[1][1] = 4;
y[0][0] = 1;
y[0][1] = 3;
y[1][0] = 4;
y[1][1] = 2;
Multiply(x, y);
;
}

I don't know why "Multiply(x,y)" cannot be translated.

If I put two "Multiply(x, y)" in the procedure, like this:

f := proc ()
local x,y;

Multiply(x, y);
x := Matrix([[1, 2], [3, 4]]);
y := Matrix([[1,3],[4,2]]);
Multiply(x, y);
NULL;
end proc;

LanguageDefinition:-Define("NewC", extend = "C", AddFunction("Multiply", [Matrix,Matrix]::Matrix,
proc (X, Y)
local a;
a := 2;
b := convert(a, string);
Printer:-Print("Mmultiply(", X);
Printer:-Print(",", Y, ")"); Printer:-Print("\n");
Printer:-Print("from", b, "to");
Printer:-Print(",", Y, "do") end proc, numeric = double));
Translate(f, language = "NewC")

THe result is:

Warning, cannot resolve types, reassigning x's type
Warning, cannot resolve types, reassigning y's type
Error, (in CodeGeneration:-IssueError) type 'Matrix' cannot be translated to target language

I don't know why type 'Matrix' cannot be translated.

### How can I access data in a matrix that's too big t...

March 22 2015
1 3

Hello!

I performed a calculation where the output was a matrix that Maple said was too big to display explicitly. So, this output was just a summary. Specifically, something like this:

How can I save/export the data inside it to another matrix so that I can manipulate it while staying within Maple?

I can export to an external file using

and then reimport the data back into Maple. But this is cumbersome.

I can also see the data on my screen by double-clicking on the matrix. But I haven't been able to manage to copy & paste it within Maple or transfer it to another matrix so I can manipulate the data. How do I do this? I'd like to stay within Maple to avoid the hassle of exporting data to Excel & then reimporting it.

Thanks,

Damian.

### Matlab matrix optimization, dimension-problems: Ma...

March 13 2015
0 0

Hi

I am trying to optimize a 39, 1 MATLAB matrix, but cannot seem to get a result beyond a 6, 1 matrix. I am getting "Warning, cannot resolve types, reassigning t##'s type" where t## varies from each time I run it, and can show multiple of these warnings. It also says "Warning, cannot translate list".

I found a pretty similar problem posted here earlier, where the user "Carl Love" suggested to replace a command from the original code with

Matlab(
subsop([-1,1]= J, eval([codegen:-optimize](tmp, tryhard), pow= ^)),
output = string, defaulttype = numeric
);

I was wondering what exactly this command does? Can I apply it to my code to solve my problem? It yielded a result that looks (on the surface) as an optimized code, but I don't feel completely comfortable using it without being certain.

What I have done is simply to replace Matlab(tmp, optimize) with the suggested code above. My code is attached. Thanks in advance for any help.

OptiMatrix.mw

### Inverting a Large Matrix...

March 12 2015
1 6

Hello,

I have 20 by 20 matrix (with only two symbolic components, say a and b), other entries of the matrix are either populated with zeros or real numbers. I am trying to obtain the inverse.

All the command I have tried returned an error message. In particular M^(-1) yields:

Error, (in radnormal/ifactors) too many levels of recursion.

I would appreciate any suggestion that could solve this issue. Thank you

ps: I am essentially trying to solve Ax=b. The commands within LinearAlgebra all yielded similar error messages.

### how to change matrix brackets from [] to () ?...

March 07 2015
1 1

When I export to latex a matrix  <<a|b>,<c|d>>, the latex uses \begin[ and \end]

\left[ \begin {array}{cc} a&b\\ \noalign{\medskip}c&d\end {array} \right]
Is there a way to make Maple use () parenthesis instead of []? The screen display is not important for me in Maple, but I'd the latex to use () instead.  It will be nice if there is way to configure this. I looked but could not find an option.

### How to sum entries in matrix based on key values?...

March 05 2015
1 6

For learning, I was trying to implement this in Maple. Given this matrix

m:=<<"foobar"   | 77>,
<"faabar"   | 81>,
<"foobaa"  | 22>,
<"faabaa"  | 8>,
<"faabian"  |88>,
<"foobar"  | 27>,
<"fiijii"      | 52>>;

And list of keys

keys:={"foo","faa"}:

The idea to find the entries (in first column) which starts with the keys, and sum the corresponding numerical value in the second column. The result will be

r:= <<"foo"|126>,
<"faa"|177>>

I tried using select, but select, once something is found, does not allow one to do anything more, so it is not very useful. For example  select[flatten](x->x[1..3]="foo",m);  just returns the fields in first column.

I can extract rows I want like this

f:=x->seq(if(m[i,1][1..3]=x,m[i],NULL),i=1..7):
r:=map(f,keys);

Not very useful, but at least I got the parts I want, but still need to process these again.

I could write a loop to do the whole thing, but I am trying to avoid this.

What would be the correct Maple way to do this? I think there might be a command in some package that will do this in one or 2 lines only.

### How to solve a Jacobian in maple?...

March 03 2015
1 3

For example, given a 3d point p(x,y,z), with (x,y,z) as its coordinates. Then it is transformed by rotation and translation, as

p'=R(p)*p+t(p), where R(p) is a 3x3 rotation matrix that is a matrix of functions of p, and t(p) is a 3x1 vector function of p.

My question is how to derive dp'/d(as a 3x3 matrix) using maple?

To make it clear,I want to do it in a way that dp'/dp = ∂p'/∂p + ∂p'/∂R*∂R/∂p +  ∂p'/∂t*∂t/∂p

And I'd like to know each intermediate quantity, such as p'/∂R, R/∂p.

Anyone can help?

Thanks a lot.

### How do I assign an indexed variable λ to change fo...

March 01 2015
1 3

Hi
I have my question makes any sense. I am from Denmark and not used to write math in english.

I have an characteristic matrix with an variable λ that takes on differen values.

How do I write λ in the matrix so Maple knows that when I call out a row with the variable λ in it and asssign

λ to a specific value, Maple changes λ to the specific value.

Example (I was thinking something like this):

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

λ_1:=2

λ_2:=4

A[1],λ_1               (1-2) 2

A[1],λ_2               (1-4) 2

A[2],λ_1               3 (4-2)

A[2],λ_2               3 (4-4)

### How do I generate all 4x4 rank-1 matrices over the...

February 19 2015
1 9

I want to generate all 4x4 matrices of rank-1 over the field with two elements, F_2. I don't want to use actual arrays though, I just want to use symbols representing the unit matrices. So for example Eij represents the 4x4 matrix with a 1 in row i & column j, and 0's elsewhere.

We have 16 unit matrices: E11, E12, ..., E14, ... E41, E42, E43, E44. Then we have to look at all possible linear combinations that result in a rank-1 matrix. So for example: E11+E12,  E11+E21,  E11+E12+E13,  E33+E43, etc. The total number of rank-1 4x4 matrices over F_2 is 225. How can I find all of these quickly?

### Sort Arrays of MAtrix to Ordered Pairs...

February 18 2015
0 6

Hi

I need sort data of an imported matrix to ordered pairs.

'M' is a matrix with 2 columns and unknown numbers of row.

with(LinearAlgebra):

M := RandomMatrix(12, 2);

pairs := [M[1], M[2], ... , M[numelems(DeleteColumn(M, [1]))]];

with(CurveFitting):

PolynomialInterpolation(pairs, x);

### inhomogenous differential equation system (Matrix)...

February 17 2015
0 1

Hey guys, I'm new to the forum, so please tell if I need to set up the question in a different way :) I've tried to find an answer for this, but have struggled since our learning book is in danish, so the used terms may not be technically correct,

Anyways, how do you solve this problem in maple?

Find the complete real solution for the differential equation system:

For the homogenous part I've found. (Is this correct?)

, c1,c2 € R

I've tried to find an answer for the inhomogenous part but I get a really complicated result, so I doubt it's correct.

Thanks for the help :)

-Alex

### Taking the standard deviation of the top row of a ...

February 12 2015
1 2

I have a markov matrix that is 500x500. I need to take the standard deviation of the top row of this matrix after I raise it to high powers, like 10^17 by 10^12, (from a do loop.) I would also like ot make a histogram of this data too.

Any ideas what I can do?

### showing that a vector x is in the rowspace of a ma...

February 10 2015
1 5

I've got a vector x=[0.36,1.3279,1.6882] (1*3) obtained as x:=pseudoInverse(A)*b where A=[<2,4,1>|<1,-1,1>|<3,3,2>] where <2,4,1>,<1,-1,1>,<3,3,2> are the columns of A and b is [8,5,4](1*3). Now, when I find the rowspace of A using RowSpace(A) I get the row vectors <1,0,1> and <0,1,1>, neither of which are equivalent to x. How do I arrive at my result that x is in the rowspace?

### find solutions to the normal equations (A^T).A.x=(...

February 09 2015
0 1

where A^T is the transpose of A and it's given that (A^T).A is not invertible.

I am stuck as to how to arrive at the solution for x in this case. I initially thought I could multiply both sides by the inverse of A^T reducing it to Ax=b but that was obviously wrong since A^T is itself not invertible(it is singular).

### how to make a string like this using cat...

January 30 2015
1 4

Hello people in Mapleprimes,

From a matrix, I want to make a string.

pt3 := Matrix(4, 2, [1, 3, 4, 5, 6, 8, 5, 10]);

string1 := cat(

"(", convert(pt3[1, 1], string), ",", convert(pt3[1, 2], string), ",", ")",

"==",

"(", convert(pt3[2, 1], string), ",", convert(pt3[2, 2], string), ",", ")",

"==",

"(", convert(pt3[3, 1], string), ",", convert(pt3[3, 2], string), ",", ")",

"==",

"(", convert(pt3[4, 1], string), ",", convert(pt3[4, 2], string), ")"

)

The above code makes

string1 := "(1,3,)==(4,5,)==(6,8,)==(5,10)"

What I want to know is how to write a code of programming without writing each row of the above code.

Actually, though I wrote 4 row matrix above, the number of rows of matrix I want to deal with might be more than 100.

Best wishes.

taro

 1 2 3 4 5 6 7 Last Page 1 of 34
﻿