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] Assignment

Search email archive for  

[MUG] Assignment
Author: Edgar G Goodaire    Posted: Tue, 04 Jun 2002 14:12:36 -0230

>> From: "Edgar G. Goodaire" "edgar"

After many years, I have still kept caught up on Maple's assignment and
unassignment rules.

What follows makes perfectly good sense to me.

> a := 7;

a := 7

> x := a;

x := 7

> x := x;

x := 7

> a :=5;

a := 5

> x;

7

What follows does not!
A := matrix(2,2,[0,0,0,0]);
[0 0]
A := [ ]
[0 0]

> X := A;

X := A

> X := X;

X := A

> A := matrix(2,2,[1,1,1,1]);

[1 1]
A := [ ]
[1 1]

> evalm(X);

[1 1]
[ ]
[1 1]

How can I get around this "problem"? ...............Edgar


========================================================================
Edgar G. Goodaire "edgar"
Mathematics and Statistics http://www.math.mun.ca/~edgar
St. John's, Newfoundland Phone: (709) 737-8097/8784
Canada A1C 5S7 Fax: (709) 737-3010
http://www.math.mun.ca/~aarms/ http://www.apics.dal.ca/index2.html
========================================================================

[MUG] Re: Assignment
Author: Maple User Group    Posted: Tue, 11 Jun 2002 17:31:17 -0400

>> From: Maple User Group "maple_gr"

| >> From: "Edgar G. Goodaire" "edgar"
| After many years, I have still kept caught up on Maple's assignment and
| unassignment rules.
| [...]
| > X := X;
|
| X := A

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

Date: Wed, 5 Jun 2002 13:51:52 -0700 (PDT)
From: Robert Israel "israel"
To: "maple-list"
Subject: Assignment


It's "last name evaluation". See "Last name evaluation" in my Maple
Advisor Database, http://www.math.ubc.ca/~israel/advisor:
-----------------
Normally, when you enter an expression it is evaluated completely. If
your expression contains a variable that has a value, the variable is
replaced by that value; if it contains a function call such as f(x), where
f is a procedure or function, then this is replaced by the value returned
by f with argument x. And if those values in turn contain variables or
function calls, they are also evaluated. Eventually (we hope) Maple
obtains a form that does not require any further evaluation, and this is
what it returns to us. However, certain types of object have special
evaluation rules. In particular, tables, arrays (including vectors and
matrices, but not Vectors or Matrices) and procedures use last name
evaluation. This means that if the result of one level of evaluation of a
name would be a table, array or procedure, then the chain of evaluation
stops with that name.
---------------

This occurs when you say "X:= A;": the right side is only evaluated as far
as the name A, because another level of evaluation would yield an array.
So X is assigned the name A, rather than the actual matrix. The result
is that when you change A, X is affected.

If by getting around this problem you mean that you want to assign X the
matrix rather than the name, you could say

> X:= eval(A);

This evaluates A fully (to a matrix) before assigning the value to X.
Note that X and A now point to the same structure. If you reassign A
by "A:= ...", X will not be affected. However, any changes to the
matrix will affect both A and X, e.g. if you say "A[1,2]:= 3;" it will
make X[1,2] be 3 also. On the other hand, you could say

> X:= copy(A);

which will assign X a new matrix that has the same entries as A, but
changes in one will not affect the other.

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


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

Date: Wed, 5 Jun 2002 19:07:04 -0400 (EDT)
From: Edwin Clark "eclark"
To: "Edgar G. Goodaire" "edgar"
Subject: Assignment


Use copyinto:

> with(linalg):
> A := matrix(2,2,[0,0,0,0]);
> X:=matrix(2,2);
> copyinto(A,X,1,1);

> A:=matrix(2,2,[1,1,1,1]);

> evalm(X);

[0 0]
[ ]
[0 0]

> evalm(A);

[1 1]
[ ]
[1 1]


------------------------------------------------------------
W. Edwin Clark, Math Dept, University of South Florida,
http://www.math.usf.edu/~eclark/
------------------------------------------------------------



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

Date: Thu, 06 Jun 2002 10:12:39 +0200
From: Adri van der Meer "A.W.J.vanderMeer"
To: "maple-list"
Subject: Assignment

This is an example of "last name evaluation"
If the right hand side of an assignment statement is a
matrix (or a procedure, a table, etc.), then is is not
evaluated to its value.
So, after X := A; the name X points to the object with
name A.
So, X is not a new matrix, but only a pointer to matrix A.
This implies: if the value of A is changed, the value of X
(on full evaluation) as also changed.

> > X := X;
> X := A

Evaluation of right hand side: X points to A, A is the "last name".


>
> > A := matrix(2,2,[1,1,1,1]);

Use:
X := copy(A);
This creates a new matrix X with the same entries as A.
Now X exists independently of A.

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




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

From: "Dr Francis J. Wright" "F.J.Wright"
To: "\"Edgar G. Goodaire\"" "edgar"
Subject: Assignment
Date: Thu, 6 Jun 2002 12:53:51 +0100

By using rtable-based matrices instead of table-based matrices, i.e. use
Matrix instead of matrix (and then don't use evalm). This only applies to
Maple 6 and later. Alternatively, use eval (or evalm) to force full
evaluation, e.g.

X := eval(A);

would give what I assume you wanted.

The reason is to do with Maple's evaluation rules rather than how it handles
assignment. A variable whose value is a table-based data structure or a
procedure evaluates by default to itself rather than its value, as you see
above. This does not apply to rtable-based values, which behave more like
algebraic values.

Francis



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

From: "Thomas Richard" "t.richard"
To: "maple-list"
Subject: AW: Assignment
Date: Thu, 6 Jun 2002 14:08:38 +0200


This way, only a pointer is copied (sometimes called a "shallow copy").
For copying the actual data structure (a "deep copy"), use
X:=evalm(X);
or (more general, works for arrays, tables and rtables):
X:=copy(X);

--
Mit freundlichen Gruessen / best regards
Thomas Richard Tel.: +49-241-40008-52, Fax: -13
Maple Support "mailto:maple.support"
Scientific Computers GmbH <http://www.scientific.de>

Previous by date: [MUG] Waterloo Maple, Inc. testing standards?, Vladimir Bondarenko
Next by date: [MUG] Re: Maple --> Mathematica convertion,  Dr Francis J Wright
Previous thread: [MUG] Plotting a point, Peter Harmand
Next thread: [MUG] Maple --> Mathematica convertion, Vladimir Bondarenko



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

What's New in Maple 11 for Professionals
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