Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: set option flag in function definition
Replies: 1   Last Post: Sep 19, 2012 4:57 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Alexei Boulbitch

Posts: 479
Registered: 2/28/08
Re: set option flag in function definition
Posted: Sep 19, 2012 4:57 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear Experts,

I had one question regarding to the function definition.

I want to have a function that executes certain operation when I chose the
corresponding option flag.

For example,

a function called "f"

when I call it like f[arg1,arg2,arg3, optionX]
it executes command
arg1/arg2+arg3

If I call it like f[arg1,arg2,arg3,optionY]
it executes command
arg1*arg2-arg3

If I call it like f[arg1,arg2,arg3,optionSomethingElse]
it returns me
"No appropriate option flag was found. Please indicate correct options"

This looks a bit like scripts running in UNIX. I am wondering if I can do
the same in Mathematica easily?

Thank you so much for your kind help!


The trivial solution would be to use If operator or a Piecewise function. For example:

f[arg1_,arg2_,arg3_, option_]:=If[option==optionX, arg1/arg2+arg3,
If[option==optionY, arg1*arg2-arg3, Print["No
appropriate option flag was found. Please indicate correct options"]
]
]

Is it unacceptable for whatever reason?

Have fun. Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone : +352-2454-2566
Office fax: +352-2454-3566
mobile phone: +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.