## 531 Reputation

18 years, 312 days

## if statement...

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) );

## Unexpected Solution...

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.

## ListTools:-Search...

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) ) ];

## evaln...

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.

## plots[display]...

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.

## Escape...

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

## Two methods...

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

## Type...

Try this: `[> select( type, k, sqrt );` --Schivnorr P.S. - *shakes his fist at Robert* Slipping in when I wasn't looking. Why I oughta... :)

## Thank you all...

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. :)

## Two methods...

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

## The same way you would define it by hand...

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```
``` ```
``` Two ways... Answered: Schivnorr 531 November 07 2007 0 5 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 A solution... Answered: Schivnorr 531 October 25 2007 0 1 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 More compact way... Answered: Schivnorr 531 October 25 2007 0 1 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 (a) is easy, at least... Answered: Schivnorr 531 October 22 2007 0 0 Just remember that for a matrix A, det( exp(A) ) = exp( tr(A) ). ```
``` 1 2 Page 1 of 2 ```
``` ```
``` ﻿ .ui-dialog{font-size: 90%;} .shareTitle { font-family: 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 1.1em; font-weight: bold; font-style: normal; color: #3366CC; } .shareTopic { font-family: 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size: 1.1em; font-weight: bold; font-style: normal; color: Black; } .shareMain { width:400px; height:490px; /* boder radius*/ -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; border-style:outset; padding-top:5px; } .roundBody { /* boder radius*/ -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; border-style:outset; padding-top:5px; } .sharelink { background-image:url("/images/share/link2.png"); background-position:0 25%; background-repeat: no-repeat; float: left; width: 255px; padding-left: 24px; margin-top:10px; margin-left:20px; } .shareButton { cursor:pointer; text-decoration:underline; } .textInput { width:329px; color:Gray; margin-top:10px; margin-left:20px; resize: none; } .FBtextInput { width:250px; color:Gray; margin-top:10px; margin-left:5px; resize: none; } .shareURL { width:320px; color:Gray; margin-top:10px; resize: none; } .shareOptions { float: left; width: 355px; margin-top:20px; margin-left:20px; margin-bottom:10px; float: left; } .shareIcons { float: left; margin-left:8px; cursor:pointer; } .shareFooter { height:60px; width:400px; background-color:Silver; margin-top:10px; position:fixed; top:437px; overflow:hidden; -webkit-border-bottom-right-radius: 10px; -webkit-border-bottom-left-radius: 10px; -moz-border-radius-bottomright: 10px; -moz-border-radius-bottomleft: 10px; border-bottom-right-radius: 10px; border-bottom-left-radius: 10px; } .footerButtonWhite { border-radius: 4px 4px 4px 4px; box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.07); cursor: pointer; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); font-family: "lucida grande",tahoma,verdana,arial,sans-serif; line-height: 26px; margin-top:20px;; margin-right:20px; float: right; } .footerButtonBlue { background: #1e5799; /* Old browsers */ background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */ background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */ border-radius: 4px 4px 4px 4px; box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.07); cursor: pointer; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); font-family: "lucida grande",tahoma,verdana,arial,sans-serif; line-height: 26px; margin-top:20px;; margin-right:20px; float: right; } .modal { text-align: center; } @media screen and (min-width: 768px) { .modal:before { display: inline-block; vertical-align: middle; content: " "; height: 100%; } } .modal-dialog { display: inline-block; text-align: left; vertical-align: middle; } .ui-dialog { z-index: 1000 !important ;} .ui-progressbar .ui-progressbar-value { background-image: url(/images/pbar-ani.gif); } .style1 { width: 377px; } .style2 { height: 35px; width: 403px; text-align: center; } .style3 { height: 70px; width: 403px; text-align: center; font-size: small; } .style4 { height: 39px; width: 403px; text-align: right; } .style5 { font-weight: normal; } .style6 { font-size: x-small; } Please log-in to your MaplePrimes account. Wrong Email/Password. Please try again. E-Mail Address: Password: Remember Me: Automatically sign in on future visits Forgot your password? Create a New Account ```
``` Ask a Question Create a Post ```
``` ```
``` ```
``` ```
``` Connect with Maplesoft: Questions  |  Posts  |  Tags  |  Users  |  Unanswered  |  Maplesoft Blog  |  Badges  |  Recent About  |  MaplePrimes Help  |  Support © Maplesoft, a division of Waterloo Maple Inc. document.write(dateObject.getFullYear()); .  |  maplesoft.com  |  Terms of Use  |  Privacy  |  Consent Preferences  | Trademarks ```
``` Generating PDF… PDF ready for download. Error occurred during PDF generation. Please refresh the page and try again Login to Your MaplePrimes Account E-Mail Address: Password: Remember Me: Automatically sign in on future visits Forgot your password? Create a New Account \$('#loginModel').on('shown.bs.modal', function() { \$('#userModelEmail').focus(); }) \$(window).load(function(){ setTimeout(function() { if (\$(".termly-styles-message-e9e76f").text().indexOf("<cookiePolicyLink>") > -1) { \$(".termly-styles-message-e9e76f").text(\$(".termly-styles-message-e9e76f").text().replace("<preferencesLink>Preferences</preferencesLink>", "Preferences").replace("<cookiePolicyLink>Cookie Policy</cookiePolicyLink>", "Cookie Policy")); } }, 100); }); ```