pagan

5147 Reputation

23 Badges

17 years, 122 days

 

 

"A map that tried to pin down a sheep trail was just credible,

 but it was an optimistic map that tried to fix a the path made by the wind,

 or a path made across the grass by the shadow of flying birds."

                                                                 - _A Walk through H_, Peter Greenaway

 

MaplePrimes Activity


These are replies submitted by pagan

Adjusting the procedure p above, to enforce a maximal step, would be simple. Add a new parameter, maxstep, and augment the check in the select call to ensure that

nops(t)=(N-1) and max(t)<=maxstep.

Adjusting the procedure p above, to enforce a maximal step, would be simple. Add a new parameter, maxstep, and augment the check in the select call to ensure that

nops(t)=(N-1) and max(t)<=maxstep.

One aspect that was not described by the OP was the distribution of the inner values (given that the two end values are specified). The routine GenerateRandomOrderedSequence will not produce values uniformly distributed between the lower and upper values (there is a bias toward the upper end).

The GenerateRandomOrderedSequence routine also does not allow specification of the number of values. Altering it to do so by a simple break (upon attaining the requested total) would still have the issue above.

An alternate scheme might use the combinat package.

> p := proc(A,B,N)
> local L,res,i,C;
>  C:=combinat:-partition(B-A,B-A-N);
>  L := select(t->nops(t)=N-1,C);
>  L := combinat:-randperm(L[rand(1..nops(L))()]);
>  res:=[A]:
>  for i from 1 to nops(L) do res:=[op(res),res[-1]+L[i]]: end do;
>  return res;
> end proc:
>
> p(0,20,6);
                             [0, 1, 8, 11, 12, 20]

> p(0,20,6);
                             [0, 1, 9, 14, 17, 20]

> p(0,20,6);
                             [0, 3, 6, 8, 16, 20]

> p(0,20,6);
                             [0, 2, 6, 16, 18, 20]

One aspect that was not described by the OP was the distribution of the inner values (given that the two end values are specified). The routine GenerateRandomOrderedSequence will not produce values uniformly distributed between the lower and upper values (there is a bias toward the upper end).

The GenerateRandomOrderedSequence routine also does not allow specification of the number of values. Altering it to do so by a simple break (upon attaining the requested total) would still have the issue above.

An alternate scheme might use the combinat package.

> p := proc(A,B,N)
> local L,res,i,C;
>  C:=combinat:-partition(B-A,B-A-N);
>  L := select(t->nops(t)=N-1,C);
>  L := combinat:-randperm(L[rand(1..nops(L))()]);
>  res:=[A]:
>  for i from 1 to nops(L) do res:=[op(res),res[-1]+L[i]]: end do;
>  return res;
> end proc:
>
> p(0,20,6);
                             [0, 1, 8, 11, 12, 20]

> p(0,20,6);
                             [0, 1, 9, 14, 17, 20]

> p(0,20,6);
                             [0, 3, 6, 8, 16, 20]

> p(0,20,6);
                             [0, 2, 6, 16, 18, 20]

Entering include in the Search box of the Online Help produced 42 pages of hits. That's over 1200 hits.

And include wasn't even on the first few pages. Sure, Preprocessor was in the top reported hits, but that's of very little use since one has to first read the page before seeing that it's relevant. Showing the exact match (on account of help aliases) would be much better.

The underlying search code should have a fast check of an exact match and push that up to the top of the results.

For Matrix A, the syntax A[1] could be replaced by A[1,1..-1] and work in any release from Maple 6 onwards.

But `Equate` was only added in Maple 10, so that's the interesting bit to replicate.

For Matrix A, the syntax A[1] could be replaced by A[1,1..-1] and work in any release from Maple 6 onwards.

But `Equate` was only added in Maple 10, so that's the interesting bit to replicate.

In Maple 9.5.1, define T as
T:=table([seq(A[1,i]=A[2,i],i=1..op([1,2],A))]):
In Maple 9.5.1, define T as
T:=table([seq(A[1,i]=A[2,i],i=1..op([1,2],A))]):
plot([1+cos(x),sin(x),x=0..Pi/2]);
plot([1+cos(x),sin(x),x=0..Pi/2]);

As John mentions, that is a "very garbagey way" to create a list. There's no need to use a method with order N^2 complexity when order N complexity schemes are readily available. (See later suggestions for using `seq`, or populating a pre-allocated Vector, etc).

As John mentions, that is a "very garbagey way" to create a list. There's no need to use a method with order N^2 complexity when order N complexity schemes are readily available. (See later suggestions for using `seq`, or populating a pre-allocated Vector, etc).

You wish to apply some operation to all entries of a Matrix (or Vector)? You can use `map` for that.

For example,

> M := Matrix([[1,2],[3,4]]);
                                      [1    2]
                                 M := [      ]
                                      [3    4]

> map( t->t^2, M);
                                   [1     4]
                                   [       ]
                                   [9    16]

Just replace the operator t->t^2 with an operator or procedure that does your simplification.

There is no intrinsic need to convert the 3x3 Matrix to a Vector in order to use `map`.

You wish to apply some operation to all entries of a Matrix (or Vector)? You can use `map` for that.

For example,

> M := Matrix([[1,2],[3,4]]);
                                      [1    2]
                                 M := [      ]
                                      [3    4]

> map( t->t^2, M);
                                   [1     4]
                                   [       ]
                                   [9    16]

Just replace the operator t->t^2 with an operator or procedure that does your simplification.

There is no intrinsic need to convert the 3x3 Matrix to a Vector in order to use `map`.

First 67 68 69 70 71 72 73 Last Page 69 of 81