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 Facebook Adept Scientific on Twitter Adept Scientific on YouBube Adept Scientific on LinkedIn


The Next Steps

• Ask us a question
• Watch Maple Video Demonstrations
• 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 16 Overview
Maple 16 Professional
Maple 16 Academic
Maple 16 Student Use
What's New in Maple 16
Maple New Features
Datasheet

Maple History
Recorded Online Seminars

MapleSim
MapleNet
Maple T.A.
BlockImporter™
Maple Toolboxes

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] Function argument name

Search email archive for  

[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



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 16 & MapleSim 5 Professional Brochure
Maple 16 Academic Datasheet
Maple 16 & MapleSim 5 Academic Brochure
Maple 16 What is New datasheet
Maple 16 Professional Datasheet
Maple Whitepaper: Driving Innovation - How mathematical modeling and optimisation increase efficiency and productivity in vehicle design.
MapleSim Whitepaper - Technological Superiority in Multi-Domain Physical Modelling and Simulation

Latest Downloads

Maple 16 Programming Guide
Maple 16 User Manual
Maple 16 Academic Datasheet
Maple 16 Professional Datasheet
Maple 16 & MapleSim 5 Academic Brochure

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

Connectivity to major CAD systems extended in Maple 16
MapleSim Breaks New Ground in Hardware-in-the-Loop real-time simulation for planetary rovers
MapleSim Breaks New Ground in Hardware-in-the-Loop real-time simulation for planetary rovers
Maths software usability reaches new heights with Maple 16
"MapleSim was an eye-opener for us.
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