Schivnorr

526 Reputation

7 Badges

14 years, 3 days

MaplePrimes Activity


These are answers submitted by Schivnorr

The easiest way would be to use a simple if statement.

 

for i from 1 to n do
for j from 1 to n do
  if i<>j then A[i,j] := rand(); fi;
od;
od;

 

Or, use the Matrix command instead of a loop.

A:= Matrix(n,n, (i,j) -> `if`(i<>j,rand(),NULL) );

 

It turns out that ArrayTools:-Copy does the same thing as N:=M in the loop.  What does work, however, is N := evalm(M).

Hooray for deprecated commands. 

If there are no repeated entries in x, then the Search command in the ListTools package will construct the index list you desire.

 

x:= [1,5,3,7];
y:= sort(x);
Ind := [ seq( ListTools:-Search( x[i], y ), i=1..nops(x) ) ];

The evaln command seems to produce the results you desire.

 

for i from 1 to 2 do
a[i]:=b[i]+c[i];
od:
L:= [ seq( evaln(a[i]) = a[i], i=1..2) ];

Also, creating the blank list L and then re-forming the list every time you iterate in your for loop can become troublesome (time and memory-management intensive) the larger L grows.

The display command in the plots package should have all the tools to do what you want.

 

Let's say that you've created your array A[i], i=1..m.

plots[display](seq(A[i], i=1..m));  will display all plots A[i] atop one another on a single set of axes.

plots[display](seq(A[i], i=1..m), insequence=true);  will create an animation that will display each A[i] in sequence one after another.  I'd recommend you look at the animate command in the plots package if you want to create animations, as it will produce smoother transitions.

If you would like all of the A[i] displayed side-by-side, use the Matrix command in conjunction with display.

plots[display](Matrix(1,m.(i,j)->A[j]));

It may be more convenient in this case, however, to define a two-dimensional array of plots, A[i,j], and then display the m-by-n matrix of plots

plots[display](Matrix(m,n,(i,j)->A[i,j]));

 

I hope these suggestions are of use. 

In the Standard Input (Math) mode, you need to explicitly escape the underscore character in order to have it appear as you would like it. To type in dperiodic_sols, you would have to type dperiodic\_sols --Schivnorr
You could use the seq() command: [> mzp:= proc(p::posint) return [seq( seq( seq( seq( Matrix([[i,j],[k,l]]), l=0..p-1), k=0..p-1), j=0..p-1), i=0..p-1)]; end proc: This code is actually rather slow. A faster method would be to construct a vector: [> m2p:= proc(p::posint) local v,i,j,k,m,n; v:=Vector(p^4); n:=1; for i from 0 to p-1 do for j from 0 to p-1 do for k from 0 to p-1 do for m from 0 to p-1 do v[n]:=Matrix([[i,j],[k,m]]): n:=n+1; od; od; od; od; return v; end proc: --Schivnorr
Try this: [> select( type, k, sqrt ); --Schivnorr P.S. - *shakes his fist at Robert* Slipping in when I wasn't looking. Why I oughta... :)
It still amazes me how quick this forum can be some times. I hadn't thought that such a simple recursive procedure would be able to do the trick, but wow. And fold ... looks like I've got some investigating to do. :)
If I'm interpreting your question correctly, I can see two immediate ways of doing this: First, you could treat the two functions x(T) and z(T) as functions of two variables, x(T,u) and z(T,u), and create a 3D plot. e.g. [> x := sin(T+u): [> z := u*sin(T): [> plot3d( [x,z], T=-Pi..Pi, u=0..2, axes=frame, color=[red,blue] ); This way, you can show how either function changes as T or u change. The other way you could do this is to create an animation. Using the same x and z as above: [> plots[animate]( plot, [[x,z], T=-Pi..Pi, color=[red,blue]], u=0..2, frames=30 ); I hope this is of some help. --Schivnorr
Here's a simple example. Hopefully, it illustrates what you are trying to do:
[> x := t -> cos(t);
                              x := t -> cos(t)
[> f := q -> q^2 + 3*q - 1;
                                      2          
                           f := q -> q  + 3 q - 1
[> f(x(t));
                                 2               
                           cos(t)  + 3 cos(t) - 1
[> diff( f(x(t)), t );
                         -2 cos(t) sin(t) - 3 sin(t)

NB: The choice of variables above, t and q, is somewhat arbitrary. --Schivnorr
We've found two ways that tend to work well in grabbing the endpoints of a range: lhs/rhs and op [> R:= a..b; [> lhs(R); a [> rhs(R); b [> op(1,R); a [> op(2,R); b Also, if you're going to use min in your procedure, you should restrict the endpoints of your ranges to real values. [> lower := proc(r::range(realcons)) min(lhs(r),rhs(r));end proc; --Schivnorr
I don't know how satisfying this solution will be, but: [> restart;with(plots): [> p1 := plot(sin(x), x=-Pi..Pi, y=-1..1): [> t1 := textplot([Pi/2, 0.9, Typesetting:-Typeset( p[gt]^`*` ) ): [> display(p1,t1); Pchin already noted the difficulty of putting the asterisk in the exponent, which is why I had to include it surrounded by backticks (``). --Schivnorr
There is a more compact way to do this than what acer described, and it will likely do better with memory allocation. Also, I've run into interesting errors when trying to re-define a single entry in a large list or vector. N:= 10^6; R := [ add( rand(0..1), k=1..12 )-6$N ](): --Schivnorr
Just remember that for a matrix A, det( exp(A) ) = exp( tr(A) ).
1 2 Page 1 of 2