Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] max element

Search email archive for  

[MUG] max element
Author: Maple User Group    Posted: Thu, 13 Feb 2003 09:10:33 -0500

>> From: Maple User Group "maple_gr"

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

To: "maple-list"
Subject: max element of array
Date: Fri, 31 Jan 2003 08:23:26 +0000
From: "A. van der Meer" "meerawj"


On 1/28/2003 "Jeffrey.Dambacher" wrote:
>
>>> From: "Jeffrey.Dambacher"
>
>-------------------------------------------------------------------
>The problem is to find the maximum value of elements of a given array,
of
>length n, where elements of the array and length vary from one
application
>to another.
>
>A fixed example given here, where
>n:=5:
>w:=array(1..n,[1,4,5,3,2]):
>
>how do I pull out the max value of w without listing each w[j] element of
w
>as above? While I can do it for the above n=5 example with:
>
>max(w[1],w[2],w[3],w[4],w[5]):
>
>If I want to evaluate an array of length 4 or 6, I would have to either
add
>or subtract a w[j] element from the above command. I need to work off
of
>one command for any size of n. It seems that
>
>max(w[1..n]);
>
>or
>
>max(entries(w));
>
>should work, but they does not.

The command

max(op(convert(w,set)));

will work for arrays of all lengths.
Explanation: max( ) requires a sequence of numbers as arguments.
entries(w) returns a sequence if lists that can not simply used as
arguments for max.



A. van der Meer
University of Twente
Dept. of Applied Mathematics
P.O.Box 217 7500AE Enschede
tel 053 489 4293
room WB-N232


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Fri, 31 Jan 2003 11:16:15 -0500 (EST)
From: Carl Devore "devore"
To: "maple-list"
Subject: max element of array



On Tue, 28 Jan 2003 "Jeffrey.Dambacher" wrote:
> how do I pull out the max value of w without listing each w[j] element of w
> as above? While I can do it for the above n=5 example with:

max(map(op, [entries](w))[]);

That gracefully handles the case of undefined entries.

> It seems that
> max(w[1..n]);
> or
> max(entries(w));
> should work, but they does not.

The .. substructure index notatation works with rtables, not arrays. It
is meaningless (but does not generate an error) with arrays. Your attempt
with entries did not work because entries returns each element in
brackets. Mine strips off those extra brackets.


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: "Dr Francis J. Wright" "F.J.Wright"
To: "Jeffrey.Dambacher"
Subject: max element of array
Date: Fri, 31 Jan 2003 16:21:15 -0000

From: "Jeffrey.Dambacher"
To: "maple-list"
Sent: Tuesday, January 28, 2003 4:54 AM
Subject: [MUG] max element of array


> The problem is to find the maximum value of elements of a given array, of
> length n, where elements of the array and length vary from one application
> to another.
>
> A fixed example given here, where
> n:=5:
> w:=array(1..n,[1,4,5,3,2]):
>
> how do I pull out the max value of w without listing each w[j] element of
w
> as above? While I can do it for the above n=5 example with:
>
> max(w[1],w[2],w[3],w[4],w[5]):
>
> If I want to evaluate an array of length 4 or 6, I would have to either
add
> or subtract a w[j] element from the above command. I need to work off of
> one command for any size of n. It seems that
>
> max(w[1..n]);
>
> or
>
> max(entries(w));
>
> should work, but they does not.


Max requires a *sequence* of values, and neither w[1..n] nor entries(w)
provides a suitable sequence. However, here are some approaches that work:

max(seq(w[i],i=1..n));
max(op(convert(w, set)));
max(op(map(op,{entries(w)})));
max(seq(op(e),e=entries(w)));

It's a moot question whether to use a set or a list as the intermediate data
structure in the middle two cases; in some situations it would matter, but
for maximization it doesn't.

Francis


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: Stanley J Houghton "S.J.Houghton"
Date: Fri, 31 Jan 2003 16:55:06 +0000
To: "maple-list"
Subject: max element of array

Try

max(convert(w,list)[]);

The brackets [] turns the list into a simple series
of values and max does the rest.

Regards
Stan


On Tue, 28 Jan 2003 15:54:09 +1100
"Jeffrey.Dambacher" wrote:

>
> >> From: "Jeffrey.Dambacher"
>
> Dear Maple User Group,
>
> I was wondering if there was any chance that a question I have regarding
> Maple could be put to the Maple User Group. Please let me know what
> resources are available to me in regards to the below question.
>
> Thanks for any forthcoming help.
>
> Best regards,
>
> Jeffrey Dambacher
> CSIRO Marine Research
> Hobart, Tasmania
> Australia
> "Jeffrey.Dambacher"
>
> -------------------------------------------------------------------
> The problem is to find the maximum value of elements of a given array, of
> length n, where elements of the array and length vary from one application
> to another.
>
> A fixed example given here, where
> n:=5:
> w:=array(1..n,[1,4,5,3,2]):
>
> how do I pull out the max value of w without listing each w[j] element of w
> as above? While I can do it for the above n=5 example with:
>
> max(w[1],w[2],w[3],w[4],w[5]):
>
> If I want to evaluate an array of length 4 or 6, I would have to either add
> or subtract a w[j] element from the above command. I need to work off of
> one command for any size of n. It seems that
>
> max(w[1..n]);
>
> or
>
> max(entries(w));
>
> should work, but they does not.
>




-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Fri, 31 Jan 2003 10:57:32 -0800 (PST)
From: Robert Israel "israel"
To: "maple-list"
Subject: max element of array


max expects a sequence (not a list or array) of numbers.
w[1..n] would return the whole list if w was a list, but doesn't work
for an array.
entries(w) produces a sequence, but it's a sequence of lists
[1], [4], [5], [3], [2]
The simplest way is

max(w[j]$j=1..n);

or

max(seq(w[j], j=1..n));

Or you could use

max(op(convert(w, list)));

which has the advantage of not needing to know n.

Or you could use "flatten" from my Maple Advisor Database,
available at <http://www.math.ubc.ca/~israel/advisor>:

max(flatten(w));

Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2

On Tue, 28 Jan 2003 "Jeffrey.Dambacher" wrote:

> -------------------------------------------------------------------
> The problem is to find the maximum value of elements of a given array, of
> length n, where elements of the array and length vary from one application
> to another.
>
> A fixed example given here, where
> n:=5:
> w:=array(1..n,[1,4,5,3,2]):
>
> how do I pull out the max value of w without listing each w[j] element of w
> as above? While I can do it for the above n=5 example with:
>
> max(w[1],w[2],w[3],w[4],w[5]):
>
> If I want to evaluate an array of length 4 or 6, I would have to either add
> or subtract a w[j] element from the above command. I need to work off of
> one command for any size of n. It seems that
>
> max(w[1..n]);
>
> or
>
> max(entries(w));
>
> should work, but they does not.
>


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Sun, 02 Feb 2003 00:44:43 +0100
From: Helmut Kahovec "helmut.kahovec"
To: "maple-list"
Subject: max element of array

"Jeffrey.Dambacher" wrote:

>| I was wondering if there was any chance that a question I have regarding
>| Maple could be put to the Maple User Group. Please let me know what
>| resources are available to me in regards to the below question.


The following could be a solution to your problem:

> restart;
> MAX:=(w::array)->eval(map(op,'max'(entries(w)))):
> n:=5: w:=array(1..n,[1,4,5,3,2]):
> MAX(w);

5


Helmut


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Mon, 03 Feb 2003 17:15:13 -0800
From: "Setemkia (Fawn) FallingTree" "Fawn"
To: "maple-list"
Subject: max element of array

"Jeffrey.Dambacher" wrote:

>The problem is to find the maximum value of elements of a given array, of
>length n, where elements of the array and length vary from one application
>to another.
>
>A fixed example given here, where
>n:=5:
>w:=array(1..n,[1,4,5,3,2]):
>
>how do I pull out the max value of w without listing each w[j] element of w
>as above? While I can do it for the above n=5 example with:
>
>max(w[1],w[2],w[3],w[4],w[5]):
>
>If I want to evaluate an array of length 4 or 6, I would have to either add
>or subtract a w[j] element from the above command. I need to work off of
>one command for any size of n. It seems that
>
>max(w[1..n]);
>
>or
>
>max(entries(w));
>
>should work, but they does not.
>
I haven't seen a reply posted to this question. I do know why
max(entries(w)) does not work...

Reading the documentation you will find that entries(w) returns a
SEQUENCE of LISTs. I.E.,
[1],[4],[5],[3],[2]

One could use max(op(map(op,[entries(w)])))
however max(op(convert(w,list))) is likely to be more efficient.

Where an indexfn has been used to minimize storage for a sparse
array/matrix use of rtable_elems is most likely more efficient. E.g.:
max(op(map(curry(op,2),rtable_elems(TheRTable))))



-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

From: "Peter Weigand" "peter.weigand"
To: "maple-list"
Date: Tue, 04 Feb 2003 12:12:43 +0100
Subject: max element of array

On 28 Jan 2003 at 15:54, "Jeffrey.Dambacher" wrote:

> The problem is to find the maximum value of elements of a given array,
> of length n, where elements of the array and length vary from one
> application to another.
>
> A fixed example given here, where
> n:=5:
> w:=array(1..n,[1,4,5,3,2]):
On 28 Jan 2003 at 15:54, "Jeffrey.Dambacher" wrote:


Dear Jeffrey, I think the simplest way is ton convert the array into list and pick with
op-command the elements for the maximum procedure

> w:=array(1..n,[1,4,5,3,2]):
> L:=convert(w,list):
> max(L);
5

Kind regards

Peter-----------------------------------------------------
Dr. Peter Weigand,
Chemnitz University of Technology
Faculty of Mathematics
Mail :D-09107 Chemnitz, Germany
Phone: +49 0371 531 2655
Fax : +49 0371 531 4947
E-mail: "weigand"
_____________________________________________________


-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Wed, 12 Feb 2003 15:31:13 +0100
From: PierLuigi Zezza "pierluigi.zezza"
Subject: max element of array
To: "maple-list"

Hi,
this should work

> n:=5;

n := 5

> w:=array(1..n,[1,4,5,3,2]);

w := [1, 4, 5, 3, 2]

> max(op(convert(w, set)));

5

gigi zezza


At 15.54 28/01/2003 +1100, you wrote:

> >> From: "Jeffrey.Dambacher"
>
>Dear Maple User Group,
>
>I was wondering if there was any chance that a question I have regarding
>Maple could be put to the Maple User Group. Please let me know what
>resources are available to me in regards to the below question.
>
>Thanks for any forthcoming help.
>
>Best regards,
>
>Jeffrey Dambacher
>CSIRO Marine Research
>Hobart, Tasmania
>Australia
>
>
>-------------------------------------------------------------------
>The problem is to find the maximum value of elements of a given array, of
>length n, where elements of the array and length vary from one application
>to another.
>
>A fixed example given here, where
>n:=5:
>w:=array(1..n,[1,4,5,3,2]):
>
>how do I pull out the max value of w without listing each w[j] element of w
>as above? While I can do it for the above n=5 example with:
>
>max(w[1],w[2],w[3],w[4],w[5]):
>
>If I want to evaluate an array of length 4 or 6, I would have to either add
>or subtract a w[j] element from the above command. I need to work off of
>one command for any size of n. It seems that
>
>max(w[1..n]);
>
>or
>
>max(entries(w));
>
>should work, but they does not.

My new e-mail address is
"pzezza"

[View Complete Thread]



Previous by date: [MUG] What has MAPLE 7 against Mathematica 3?, Donohue
Next by date: [MUG] Re: Problem with SWP Implementation of Maple, Robert Israel
Previous thread: [MUG] fundamental idea in a procedure - counting primes,  John A Velling
Next thread: [MUG] Problem with SWP Implementation of Maple, Jim Moser



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055