 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] evalm and mapping of function
| [MUG] evalm and mapping of function |
|
Author: Guy Gendron
Posted: Thu, 30 May 2002 09:42:32 -0400
|
>> From: Guy Gendron "ggendron"
Dear all,
I dont understand why Maple cannot map the "fcncarre" function onto the
elements of the matrix "mat_a". I am trying to use evalm to square each
element of the input matrix. It does not work with my own function
(fcncarre) but it works with sin (see example below). What is the
difference between "sin" and "fcncarre". How would I proceed to apply
a transformation to each element of a matrix without using for loops.
I am working with Maple 7 on Windows 98.
Thanks in advance,
Best regards,
Guy Gendron
> print(mat_a); # mat_a is a matrix
[1 2 3]
[ ]
[4 5 6]
> fcncarre:=x->x*x; # I define a new function
2
fcncarre := x -> x
> evalm(fcncarre(mat_a));#I want evalm to map the fonction onto each elem.
of mat_a
Error, (in linalg[multiply]) non matching dimensions for vector/matrix product
> evalm(sin(mat_a)); # It works with sin!
[sin(1) sin(2) sin(3)]
[ ]
[sin(4) sin(5) sin(6)]
|
| [MUG] Re: evalm and mapping of function |
|
Author: Maple User Group
Posted: Wed, 5 Jun 2002 14:16:12 -0400 (
|
>> From: Maple User Group "maple_gr"
> >> From: Guy Gendron "ggendron"
> I dont understand why Maple cannot map the "fcncarre" function onto the
> elements of the matrix "mat_a". I am trying to use evalm to square each
> element of the input matrix.
>
> > evalm(fcncarre(mat_a));#I want evalm to map the fonction onto each elem.
> of mat_a
> Error, (in linalg[multiply]) non matching dimensions for vector/matrix product
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 31 May 2002 17:25:33 +0200
From: Adri van der Meer "A.W.J.vanderMeer"
To: "maple-list"
Subject: evalm and mapping of function
You use the right word: "map":
> map( fcncarre, evalm(mat_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
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 31 May 2002 09:23:32 -0700
To: "maple-list"
From: David Harrington "dharr"
Subject: evalm and mapping of function
try
> map(fcncarre,eval(a));
or
> map(fcncarre,evalm(a));
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 31 May 2002 12:09:46 -0400 (EDT)
From: Denis Sevee "dsevee"
To: "maple-list" "maple-list"
Subject: evalm and mapping of function
You should use
>map(fcncarre, mat_a);
This is how, in general, you should apply any function to the entries of
a matrix.
Denis Sevee
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
From: Douglas Wilhelm Harder "douglas"
Subject: evalm and mapping of function
To: "maple-list"
Date: Fri, 31 May 2002 13:46:58 -0400 (EDT)
Your function immediately returns something:
> fcncarre:=x->x*x; # I define a new function
2
fcncarre := x -> x
> mat_a := matrix( [[1,2,3],[4,5,6]] ):
> fcncarre( mat_a );
2
mat_a
unlike sin:
> sin( mat_a );
sin(mat_a)
and you cannot square a non-square matrix. Try:
> map( fcncarre, mat_a );
[ 1 4 9]
[ ]
[16 25 36]
Cheers,
Douglas
--
Douglas Wilhelm Harder ||\_ _\ /_/\_ _/\_\ /_ _/|| MM BSc MCpl (Retd)
University of Waterloo ||\ _\ /_/\_\ /_ _/
Waterloo Fractal Compression Project _\ / _/||
"douglas" _/\_\||\_ _/ /_/\_
http://links.uwaterloo.ca/~douglas _/||\_ _/ /_/\
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Sun, 2 Jun 2002 11:43:09 -0700 (PDT)
From: Robert Israel "israel"
To: "maple-list"
Subject: evalm and mapping of function
If you told it to map, it would map.
> map(fcncarre, mat_a);
If you say fcncarre(mat_a), you are telling Maple to square the matrix.
And since this is a 2 x 3 matrix, that is impossible.
The real question is, why does sin map into the matrix. In my opinion,
that is a bug. A function of a matrix should be defined using the
functional calculus, so that
sin(M) = (exponential(I*M)-exponential(-I*M))/(2*I). Of course this would
only be defined for square matrices.
Robert Israel "israel"
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Sun, 2 Jun 2002 19:42:41 -0400 (EDT)
From: Alain Goupil "goupil"
To: "maple-list"
Subject: evalm and mapping of function
Dear mr Gendron, The command map is the standard command to map a
function on the elements of a matrix as in the following :
> mat_a:=matrix([[1,2,3],[4,5,6]]):
>fcncarre:=x->x*x:
> map(fcncarre,mat_a);
matrix([[1, 4, 9], [16, 25, 36]])
Best regards,
Alain Goupil,
On Thu, 30 May 2002, Guy Gendron wrote:
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Tue, 4 Jun 2002 09:46:57 -0400 (EDT)
From: Carl Devore "devore"
To: "maple-list"
Subject: evalm and mapping of function
map(fcncarre, mat_a);
|
Previous by date: [MUG] Re: plots[display]: Error, (in plots/object2plot) bad
object to display symbol, Robert Israel
Next by date: [MUG] Can Maple use 2 CPUs?, Vladimir Bondarenko
Previous thread: [MUG] Maple 6.0 / Redhat 7.3, Stefan Kornhuber
Next thread: [MUG] Can Maple use 2 CPUs?, Vladimir Bondarenko
|
|
|