List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Function argument name
| [MUG] Function argument name |
|
Author: Guy-Armand Kamendje
Posted: 28/11/2000 15:58:10 GMT
|
>> From: Guy-Armand Kamendje
I have somewhere the expression
Myexp=x[1]^2+x[1]*x[2]+x[3].... x[n]in the variable x[1], x[2] ..x[n]
I will like to use this expresion in oder to let maple define a function
of the form
f1:=(x[1],x[2],...x[x])->y
when passing the subscript x[i] to the function's definition, an error
message is displayed requiring a name as funtions argument. How can I
get Maple interpret the subscripts in the correct way and also evalue
the expression Myexp in the correct way within the function?
It looks like
> v_vect[1]:=
2
1 + x[1] + x[1] x[3] + x[2] x[1] + x[4] + x[4] x[5] + x[1] x[4]
2
+ x[2] x[4] + x[1] + x[2] + x[2] + x[3] x[5]
f1:=(x[1],x[2],x[3],x[4],x[5])->v_vect;
Error, name expected in argument list
What I'am doing wrong?
Thanks for any hint
--
G.A. Kamendje || Tel +43 316 873 55 51
T-U Graz || www.sbox.tu-graz.ac.at/home/g/gaillard/
I.A.I.K ||www.iaik.at/people/gkamendje/gkamendje.html
|
| [MUG] Re: Function argument name |
|
Author: Maple Group
Posted: 01/12/2000 20:14:10 GMT
|
>> From: Maple Group
>> From: Guy-Armand Kamendje
| I have somewhere the expression
| Myexp=x[1]^2+x[1]*x[2]+x[3].... x[n]in the variable x[1], x[2] ..x[n]
| I will like to use this expresion in oder to let maple define a function
| of the form
| f1:=(x[1],x[2],...x[x])->y
| when passing the subscript x[i] to the function's definition, an error
| message is displayed requiring a name as funtions argument. How can I
| get Maple interpret the subscripts in the correct way and also evalue
| the expression Myexp in the correct way within the function?
|
| It looks like
| > v_vect[1]:=
|
| 2
| 1 + x[1] + x[1] x[3] + x[2] x[1] + x[4] + x[4] x[5] + x[1] x[4]
|
| 2
| + x[2] x[4] + x[1] + x[2] + x[2] + x[3] x[5]
|
|
| f1:=(x[1],x[2],x[3],x[4],x[5])->v_vect;
|
| Error, name expected in argument list
| What I'am doing wrong?
| Thanks for any hint
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 29 Nov 2000 11:00:27 -0800 (PST)
From: Robert Israel
To:
Subject: Function argument name
There are actually two problems here. One is that you must use
non-subscripted names as formal parameters of a function. The other
is that you should use "unapply", not a construction such as "f:= x -> y",
to make an expression into a function. The reason the latter
construction won't work is the difference between global variables
and formal parameters. For example:
> y:= x+1;
> f:= x -> y;
> f(t);
x+1
The x in "y:= x+1" is a global variable. This looks the same as the
formal parameter x in the definition of f, but it is treated as completely
different. In particular, when you say "f(t)", Maple won't substitute t
for the global variable x in the value of y. Instead, you should use
> f:= unapply(y, x);
f(t);
t+1
"unapply" does allow the use of subscripted variables (automatically
changing them to non-subscripted forms). For example:
> y:= x[1]^2 + x[2]*x[3];
f:= unapply(y, x[1],x[2],x[3]);
2
f := (x_1, x_2, x_3) -> x_1 + x_2 x_3
Robert Israel
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 29 Nov 2000 16:25:38 -0600 (CST)
From: Andrzej Pindor
To:
Subject: Function argument name
It seems that a subscripted variable cannot appear in a function definition.
However, you could do something like this:
breeze{60}: maple
|\^/| Maple 6 (SUN SPARC SOLARIS)
._|\| |/|_. Copyright (c) 2000 by Waterloo Maple Inc.
\ MAPLE / All rights reserved. Maple is a registered trademark of
<____ ____> Waterloo Maple Inc.
| Type ? for help.
> v_vect[1]:=1 + x[1]^2+x[1]*x[3] + x[2]*x[1] + x[4] + x[4]*x[5] + x[1]*x[4]
> + x[2]*x[4] + x[1] + x[2]^2 + x[2] + x[3]*x[5];
2
v_vect[1] := 1 + x[1] + x[1] x[3] + x[2] x[1] + x[4] + x[4] x[5] + x[1] x[4]
2
+ x[2] x[4] + x[1] + x[2] + x[2] + x[3] x[5]
> f1:=unapply(subs(seq(x[i]=x||i,i=1..5),v_vect[1]),seq(x||i,i=1..5));
2
f1 := (x1, x2, x3, x4, x5) -> 1 + x1 + x1 x3 + x2 x1 + x4 + x4 x5 + x1 x4
2
+ x2 x4 + x1 + x2 + x2 + x3 x5
> f1(x[1],x[2],x[3],x[4],x[5]);
2
1 + x[1] + x[1] x[3] + x[2] x[1] + x[4] + x[4] x[5] + x[1] x[4] + x[2] x[4]
2
+ x[1] + x[2] + x[2] + x[3] x[5]
>
Regards
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
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Wed, 29 Nov 2000 16:40:59 -0500 (EST)
From: Denis Sevee
To:
Subject: Function argument name
Just use x as the input parameter. For example,
>f:=x->x[1]+x[2]:
>y:=[3,8]:
>f(y);
11
If you tried f:=(x[1],x[2])->x[1]+x[2] ; you would get the same error
message that you reported.
Denis Sevee
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 30 Nov 2000 12:44:13 +0100
From: Barsuhn
Subject: Function argument name
To:
Dear Guy-Armand,
use "unapply" to build up your function f1. "unapply" automatically
transforms the indexed names (illegal) into "concatinated" names
(legal). When you later on call your function, you may of course also
use indexed names as actual parameters. This piece of code works for
Maple 6 and Maple V R5.1:
> v_vect[1]:=1 + x[1]^2 + x[1]* x[3] + x[2]* x[1] + x[4] + x[4]* x[5] +
x[1] *x[4]+ x[2]* x[4] + x[1] + x[2]^2 + x[2] + x[3]*x[5];
> f1:=unapply(v_vect[1],x[1],x[2],x[3],x[4],x[5]);
> f1(y[1],y[2],y[3],y[4],y[5]);
>
The error message you got is indeed somewhat misleading, as names are
allowed to have index expressions. Maple 6 correctly asks for symbols
(i.e. names without any index expression) as formal parameters.
All the best Jurgen
--
-------------------
Prof. Dr. Jurgen Barsuhn
Fachhochschule Bielefeld
University of Applied Sciences
Fachbereich Elektrotechnik und Informationstechnik
Wilhelm-Bertelsmann-Str. 10
D-33602 Bielefeld
-----------
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 01 Dec 2000 09:21:04 +0900
To:
From: tanaka
Subject: Function argument name
I think that Maple qualifies that [ ] is not a suffix but a "list".
So parameter list is required.
Another method to make a function is to use "unapply" command.
>restart:
>v_vect[1]:=1+x[1]^2+x[1]*x[3]+x[2]*x[1]+x[4]+x[4]*x[5]+x[1]*x[4]
> +x[2]*x[4]+x[1]^2+x[2]+x[2]+x[3]*x[5]:
>unapply( v_vect[1],x[1],x[2],x[3],x[4],x[5]);
In this case, we have
(x_1, x_2, x_3, x_4, x_5) -> 1+2*x_1^2+x_1*x_3+x_2*x_1+x_4+x_4*x_5
+x_1*x_4+x_2*x_4+2*x_2+x_3*x_5
Even though, the expression [ ] is ,somehow, changed to "underbar",
this is a function of x[1],x[2],x[3],x[4] and x[5].
For example, a process
>diff(v_vect[1],x[1]);
yields 4*x[1]+x[3]+x[2]+x[4].
Dr.TANAKA, Kazuo,
Canon Inc., Tokyo, JAPAN
|
Previous by date: [MUG] Re: Stopping integration due to what?, Allan Wittkopf
Next by date: [MUG] Simplification problem, Carl Eberhart
Previous thread: [MUG] Integration bug, i think, Halvor Mehlum
Next thread: [MUG] Simplification problem, Carl Eberhart
|