# Items tagged with listlist Tagged Items Feed

### return a list of indices that match a condition...

July 25 2014
1 13

a:=Vector([2,3,4,5]);

select[flatten](x->x>=3,a);

This returns a Vector that satisfies the above condition. What's the most efficient way to get the indices of those entries?

For example, a list l:=[2,3,4] that correspond to the a[l] entries that satisfies the above condition.

l:=[2,3,4];

a[l]; # gives the same answer

Thanks,

casper

### Vectors of lists...

June 30 2014
0 5

restart;

Vector([a, b]);  <a, b>;  # Identical results

a:=[1, 2]:  b:=[3, 4]:

Vector([a, b]), <a, b>;   # Different results. Why?

### bug report: Matrix of strings...

June 21 2014 Maple
1 5

The problem is when initializing a Matrix with a list of strings. The worksheet excerpt below shows the normal behavior using a list of integers to initialize a square matrix: the successive list elements fill the matrix by rows.

Then trying the exact same thing with a list of strings instead of integers gives an error message!
This is not right. While it is an odd and likely rare problem, it would be better fixed.

x := [i \$ i=1..25];
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
Matrix(5,5,x);

y := map(convert,x,string);
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"]
Matrix(5,5,y);
Error, (in Matrix) initializer defines more columns (25) than column dimension parameter specifies (5)

### How to save values stored in the variables in a wo...

June 01 2014
0 2

My problem is i am working with a very large randomly generated output, generated using maple's builtin in random generating functions. I have the output which i want to investigate but i want to be able to reproduce this result when i save and close the worksheet. Since the list of generators is very long copy pasting is not very nice and i donot know the seed of these generaters. I want to ask if i can store the values in variable in the worksheet so that when i open the worksheet i can get the same random generates stored in the variable.

### permutation group S_n for given n : cycle, tran...

May 07 2014
1 3

Hi,

I would like to compute the elements of the permutation group, let us say S10 or S20.

Is there any method to compute all the elements.

And can we make a list of the tranposition and cycles.

Many thinks.

### Generation of a list of points and a plot from it...

May 05 2014
2 3

Is it possible to generate a list of values for a function in the form of an ordered pair, like

a cartesian plane, i.e. ( x, f(x) )? And how can I plot a graph with this output?

### Write a procedure unimodal to check whether or not...

April 23 2014
1 1

the sequence is non-decreasing up to some point after which it is non-increasing. Note that i can be 1 or n. A constant sequence is considered to be unimodal.

Examples of unimodal lists:

[1, 1, 1, 1, 1],
[1, 2, 2, 3, 4, 5, 5, 5],
[5, 5, 4, 4, 3, 3, 1],
[1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1],
[1, 2, 2, 3, 3, 3, 4, 4, 2, 2, 1, 1, 1]

Examples of lists that are not unimodal:

[1, 0, 1, 0],
[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1],
[1, 1, 2, 2, 3, 4, 5, 2, 2, 6, 4, 2, 2, 1, 0]

i don't have a clue

### return the indicis of a value from list...

April 08 2014
0 2

Hi, with a list

l:=[1,1,1,2,3,3,4];

What's the best way to get the index(s) for the values equal to '1'?

Say for x=1, we want

[1,2,3]

for x=2, we want

[4]

ect.

### pick up by the sum of the list elements...

April 04 2014
1 1

Say I have this list,

tmp:=[[0, 1, 2], [1, 0, 2], [1, 1, 2], [1, 2, 0]];

and the sums of each element (list),

map(x->convert(x,`+`),tmp);

How do I quickly pickup the elements, where they sum to 3? Like this:

wanttohave:=[[0, 1, 2], [1, 0, 2],  [1, 2, 0]];

Thanks,

### is there any built-in function equivalent to set m...

March 30 2014
1 11

Please i don't want to convert from list to set then apply set minus and convert back because it loses its order and repititions.

so i want something that can for example do the following:

list_minus([1,2,4,6,2,1,3,6,2],[7,4,2,5,2]) = [1,6,1,3,6,2]

so it removes repititions from left and order is retained.

### printf for list 0 format conversion help...

March 13 2014
0 3

Hi all,

Say I have some list like this,

tmp:=[[0, 0, 1], [0, 1, 0], [0, 1, 1], [0, 1, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0]];

And I have worked out some probabilities for each of them, a,b,c,d, ect.

I want to print them like this

Pr( 001 ) = 1

Pr( 010 ) = 1-phi[2]+phi[2]*(1-p[3])*(1-phi[3])

Pr( 011 ) = phi[2]*p[3]*(1-phi[3])

and so on.

I there a way to do that?

The probabilities can be extracted from a Vector. I have no problem to print them.

I dont know how to convert the 0,1,2 into the desired format as shown above.

This is the best I can do.

Also, is it possible to convert all the subscripte [] to _ when printing the output?

and get ride of all * as well.

Thanks,

casperyc

### how to get a list of number from decimal...

March 04 2014
1 6

assume input 0.567

how to get a list [5, 6, 7] or [5;6;7]?

### Write a procedure whose input is a binary list an...

February 21 2014
1 5

m:=proc(n::list)
local N, S, i:
N:=nops(n);
S:={};
for i from 1 to N do
if n[i]=1 then do
S:=S union {i}; break; od; fi; od;
for i from 1 to N do
if n[i]=0 then do
S:=S union {}; break; od; fi; od;
end proc;

the procedure works if the last member of a list is 0, for example

m(1,0,1,0);

returns {1,3}

but if it ends in 1, nothing gets returned, example: m(1,0,1);

I can also get it to work the other way around, where it'll return the set if the list ends in 1 but not zero. I need it to work for both.

### Orbit of 2x2 matrix through a given list of points...

February 16 2014
1 7

okay so im quite confused, im trying to write a procedure that prints the orbit of a 2x2 matrix through a given list of points.  our arguments should be a a (2x2) matrix, a list L of points represented by 2 vectors, ie (2x1) matrices and a natural number N. Returnvalue : NULL

a side effect should be to

A^i.L[j] for i = 0 ... N and j = 1 ... nops(L)

thus, an example, if the proc is called P, then

P(Matrix([[0,-1],[1,0]]),[Matrix([[1],[1]]),Matrix([[1],[0]])],2)

should plot the points

(1,1) ,(-1,1) , (-1,-1)  for the 1st point  and

(1,0)  ,(0,1) , (-1,0) for the second

thanks for any help in advance

February 15 2014
1 4

I wrote the following code inside a code region in order to implement a scalar product for lists:

m:= module() option package; export `*`;
`*`:= proc( a::list, b::list) option overload;
return add(i, i  in zip((x, y)-> x*y, a, b));
end proc;
end module;
l1:=[1,2,3,4];
l2:=[4,1,0,5];
with(m);
l1*l2;

when i run the code I sometimes get the desired result ->26

but sometimes I get

I don't have any clue, where this weird behaviour comes from.

Any help would be greatly appreciated.

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