Adept Scientific - English
The world's best software and hardware 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  
UKdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Academic Discounts
Support
My Adept
International |  About Us |  Adept Scientific Blog |  Contact Us |  Press Room |  Jobs
Adept Scientific on Twitter Adept Scientific on LinkedIn


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Download a Brochure
• Request a Brochure
• Request an Evaluation
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 15 Professional
Maple 15 Academic
Maple 15 Student Use
What's New in Maple 15
Maple Features
Maple History
Recorded Online Seminars

MapleSim
MapleNet
Maple T.A.
BlockImporter™
Maple Toolboxes

Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

Maple Home
Maple 15 Professional
Maple 15 Academic
Maple 15 Student Use
What's New in Maple 15
Maple Features
Maple History
Recorded Online Seminars

MapleSim
MapleNet
Maple T.A.
BlockImporter™
Maple Toolboxes and
Connectors


Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

Latest Information

New Features: Professional
New Features: Academic
Maple Features
The Maple Reporter Online

Service & Support

Maple Primes
blogs, forums etc

Elite Maintenance Program
Application Centre
Powertools
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] Sorting a List of Lists for Plotting

Search email archive for  

[MUG] Sorting a List of Lists for Plotting
Author: JReinmann524    Posted: 02/03/2000 17:20:19 GMT
>> From:

Hello,

I have been using "fsolve" to to solve a transcendental equation with two
parameters (a and b). I choose one parameter and solve for the other. I
then put the two values in a list [a,b]. Next, I add this list to an already
existing sequence of lists by the command.
> L:=L,[a,b];

I then plot the list [L] with the command
>plot([L]).

I always get a plot, but since the list is not ordered with respect to the
parameter 'a', the plot results in straight line segments zigzagging all over
the plot.

QUESTION 1:

Can Maple order the list with respect to the parameter 'a' ?

I have written a bubble sort procedure that does the sorting nicely, but I
wonder if Maple can do this for me. It seems like such a common requirement.

QUESTION 2:

Is there any way to add an element, say [a1,b1], to a selected position
somewhere inside of the sequence L or the list [L] ?

Thanks,

John Reinmann email:

[MUG] Re: Sorting a List of Lists for Plotting
Author: Maple Group    Posted: 06/03/2000 19:54:05 GMT
>> From: Maple Group

| >> From:
| I have been using "fsolve" to to solve a transcendental equation with two
| parameters (a and b). I choose one parameter and solve for the other. I
| then put the two values in a list [a,b]. Next, I add this list to an already
| existing sequence of lists by the command.
| > L:=L,[a,b];
| I then plot the list [L] with the command
| >plot([L]).
| QUESTION 1: Can Maple order the list with respect to the parameter 'a' ?
| QUESTION 2: Is there any way to add an element, say [a1,b1], to a
| selected position somewhere inside of the sequence L or the list [L] ?

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

From: Norbert Roth
To:
Date: Sat, 04 Mar 2000 05:22:18 +0100
Subject: Sorting a List of Lists for Plotting

Hello John,

on 02-Mar-00 you wrote :

; QUESTION 1:

Hhmm, AFAIR there exist's a sort command,
but it works only for one dimensional lists, e.g. L:=[1,7,15,...]
(But I maybe wrong at this point, try ?sort to get further info)

; QUESTION 2:

Yes, this command exists:

'subsop(i=x,L)' replaces the i-th element of the list L by x

Adding an element to the list can be done via 'op(L,x)'.

Here's a quick hack which solves your sorting problem:

> BSort:=proc(L:list)
local i,j,temp,TL;
TL:=L;
for i from 1 to nops(TL)-1
do
for j from 1 to nops(TL)-i
do
if TL[j][1] > TL[j+1][1] then
temp:=TL[j]:TL:=subsop(j=TL[j+1],TL):
TL:=subsop((j+1)=temp,TL) fi;
od;
od;
RETURN(TL)
end;

When using NL:=BSort(L),
NL will contain the sorted version of L.

Regards

NR

PS
I just had another idea how to implement a sorting
algorithm in MapleV, so here's another procedure,
it's about seven times as fast a the last one.

> StrangeSort:=proc(L:list)
local i,j,TL,LL,ML,xplace;
TL:=L:
for i from 1 to nops(L)
do
LL:=seq(TL[j][1],j=1..nops(TL)):
#for changing the sorting sequence from descending
#to ascending just change 'max(LL)' to min(LL) in
#the next line of the procedure
member(max(LL),convert([LL],list),'xplace'):
if i=1 then NL:=TL[xplace] else NL:=NL,TL[xplace] fi;
TL:=subsop(xplace=NULL,TL):
od:
NL:=convert([ML],list);
RETURN(ML):
end;

When using NL:=StrangeSort(L),
NL will contain the sorted version of L.

Regards

NR

--
Remark of the day :

Description of human morality :
We ought to.
But we dont !



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

Date: Sat, 4 Mar 2000 23:32:39 -0800 (PST)
From: Robert Israel
To:
Subject: Sorting a List of Lists for Plotting



On Thu, 2 Mar 2000 wrote:

|> QUESTION 1:
See the help for "sort". All you need to do is write a Boolean-valued
function that defines the ordering you wish to use (returning true if its
first argument is to come before the second). Thus:

> lex2:= proc(a,b)
if a[1] = b[1] then evalb(a[2] <= b[2])
else evalb(a[1] <= b[1])
fi
end;

> sort([L],lex2);


|> QUESTION 2:
(for a list: this version must be called with the name of a variable to
which the list has been assigned)
> insert:= proc(L::uneval, x, pos::posint)
assign(L,[op(L[1..pos-1]),x,op(L[pos..-1])]);
eval(L);
end;



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



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

Date: Mon, 06 Mar 2000 11:10:50 +0100
From: Adri van der Meer
To:
Subject: Sorting a List of Lists for Plotting


| QUESTION 1:
It is:

sort( [L], (x,y)->evalb(x[1]<x[2]) );

| QUESTION 2:

There is no "easy way"; you have to create a new list or
sequence. For example (if L a list)

insert := proc(element,place,L)
local K,i;
K := NULL;
for i to place-1 do K := K,L[i] od;
K := K,element;
for i from place to nops(L) do K := K,L[i] od;
[K]
end;



--
A. van der Meer
Dept. Applied Mathematics
University of Twente Phone +31 (53) 4893427
P.O. Box 217 Fax +31 (53) 4894824
7500 AE Enschede




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

Date: Mon, 06 Mar 2000 12:20:31 +0000
To:
From: Stanley J Houghton
Subject: Sorting a List of Lists for Plotting

>QUESTION 1:Can Maple order the list with respect to the parameter 'a' ?
Certainly, using the sort procedure as follows:

> sort(L,(a,b)->evalb(a[1]<b[1]));

See the help pages on sort for more details.

>QUESTION 2:

You can use basic list processing to add an element as follows, say at
position 'n':

>L:=[op(1..n-1,L),[a1,b1],op(n..-1,L)];

but it is again not very efficient. You may be better, generating the list
and then sorting it.

Hope it helps

Stan


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

Date: Mon, 6 Mar 2000 09:28:01 -0600 (CST)
From: Andrzej Pindor
To:
Subject: Sorting a List of Lists for Plotting


How about something along the folowing lines:

add_list:=proc(l_old,n,new_element) local i;
[seq(l_old[i],i=1..n-1),new_element,seq(l_old[i],i=n..nops(l_old))]
end;

For a sequence (instead of a list) just drop [] around the expression above.

Hope it helps

Andrzej
=========
Dr. Andrzej Pindor The foolish reject what they see and not what
University of Toronto think; the wise reject what they think and not
Information Commons what they see. Huang Po
Phone: (416) 978-5045 Fax: (416) 978-7705



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

From: "Symancyk, Daniel"
To:
Subject: Sorting a List of Lists for Plotting
Date: Mon, 6 Mar 2000 11:53:18 -0500

QUESTION 1
If you use sort with a boolean procedure (such as the one below
from robert Israel) you can sort your [L] the way you want.

>sortf:= proc(a,b)
if a[1] = b[1] then
evalb(convert(a[2],string) <= convert(b[2],string))
else evalb(a[1] < b[1])
fi
end;

Then use
>m:=sort([L],sortf);
>plot(m);
The graph will not zigzag.

Note: zigzag is not a problem and reordering is not needed if you are
willing to graph just points.
>plot([L],style=point);

QUESTION 2
Here is a procedure that will insert a newEntry into list L
at a specified location. The procedure uses the fact that
subsop allows you to replace an entry in a list with a new entry.

>insertL:=proc(insertLocation::posint,newEntry,L::list)
local L1,L2,j;
if nops(L)=0 then [newEntry];
else
if insertLocation<=0 or insertLocation>nops(L) then ERROR(`insertion
location must be between 1 and the number of items in the list`) fi;
L1:=L[1..insertLocation];
L2:=L[insertLocation..nops(L)];
L1:=subsop(insertLocation=newEntry,L1);
for j from 1 to nops(L2) do
L1:=[op(L1),op(j,L2)];
od;
L1;
fi;
end:

For example
>M:=[ [2,3], [3.5,7], [4,9] ];
This inserts [6,7] as the third item in M
>M:=insertL(3,[6,7],M);


Daniel F. Symancyk
Math Department
Anne Arundel Community College
Arnold, MD 21012
410-541-2587





Previous by date: [MUG] Re: Diff remember table, Maple Group
Next by date: [MUG] Re: A question about solving Laplace's PDE with Maple, HOLMGREN
Previous thread: [MUG] Plotting error: non-numeric vertex,  Tim Howard
Next thread: [MUG] A question about solving Laplace's PDE with Maple, Vassil Vassilev



Ready to buy?

For more pricing information:
Visit our webstore, call us on +1 800 724 8380 or email us at info@adeptscience.com

Featured Downloads

Maple 15 & MapleSim 5 Professional Brochure
Maple 15 Academic Datasheet
Maple 15 & MapleSim 5 Brochure - Academic Brochure
Maple 15 New Features data sheet
Maple 15 New Features - Flyer
Maple Whitepaper: Driving Innovation - How mathematical modeling and optimisation increase efficiency and productivity in vehicle design.
MapleSim Whitepaper: Technological Superiority in Multi-Domain Physical Modeling and Simulation

Latest Downloads

Maple Case Study: The Changing Face of Robotics
Maple Application Brief - Analyse the Path of a Liquid-Handling Robot
Maple Player for iPad - App
Maple Player for iPad - Datasheet
Case Study - Multi-Domain Modelling Critical to Unmanned Vehicle Designs

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

Latest News

NASA’s Jet Propulsion Laboratory begins widespread adoption of Maplesoft technology
NASA’s Jet Propulsion Laboratory begins widespread adoption of Maplesoft technology
Latest release marks the 10th anniversary of Maple T.A.
Maple Case Study: The Changing Face of Robotics
Maple Application Brief - Analyse the Path of a Liquid-Handling Robot
adept

Top of the Page

Popular Links: ChemDraw | ChemOffice | Data Acquisition | Data Analysis | EndNote | Maple | MapleSim | Mathcad | MathType | Quality Analyst | Reference Manager | VisSim

EU ePrivacy Directive | Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2012, Adept Scientific plc.
Site designed and maintained by Lyndon Ash

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