Re: Package and options, subroutines Mathematica programming 3GL function procedure

• To: mathgroup at smc.vnet.net
• Subject: [mg50668] Re: Package and options, subroutines Mathematica programming 3GL function procedure
• From: bobmarlow at postmaster.co.uk (Bob Marlow)
• Date: Wed, 15 Sep 2004 07:54:53 -0400 (EDT)
• References: <ch97qo\$ff1\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```I have written a 'subroutine' in Mathematica, shown below, which
seems to work fine, but when would it be better, or when would
I need to make it a package?

Rintegrate2D[f_, x1_, x2_, y1_, y2_, n_] := {dx = (x2 - x1)/n; dy = (y2 -
y1)/n;
Rvalue = 0; Do[Rvalue = Rvalue + f[
x1 + i*dx, y1 + j*dy], {i, 0, n - 1}, {j, 0, n - 1}];
N[dx*dy*Rvalue]}[[1]]

Example call:=

T1[x_,y_]:=x+y
z=Rintegrate2D[T1,-3,3,-3,3,100]

"David Park" <djmp at earthlink.net> wrote in message news:<ch97qo\$ff1\$1 at smc.vnet.net>...
> Guillermo,
>
> If it was part of a notebook, I would write your package something like the
> following.
>
> BeginPackage["Test1`"]
>
> fexample1::"usage" =
>     "fexample[x, opts] calculates (a + b) x where a and b are set by \
> options.";
>
> a::usage = "a is an option for fexample that sets its value.";
>
> b::usage = "b is an option for fexample that sets its value.";
>
> Begin["`Private`"]
>
> Options[fexample1] = {a -> Global` A, b -> Global` B};
> fexample1[x_, opts___Rule] :=
>   (a + b) x /. {opts} /. Options[fexample1]
>
> End[]
> EndPackage[]
>
>
> Then
>
> ?Test1`*
>
> gives usage messges for a, b and fexample1 and
>
> fexample1[x]
> (A + B) x
>
> Notice that I moved the Options statement to the Private section and I used
> Global`A and Global`B to set the default values of a and b. Also you want to
> start the usage message with the function name and arguments to get
> automatic command completion when desired.
>
> David Park
>
>
> From: Guillermo Sanchez [mailto:guillerm at aida.usal.es]
To: mathgroup at smc.vnet.net
>
>
> Dear friends
>
> Here is a example package:
>
> (*Title : Package for testing options*)
>
> BeginPackage["Test`Test1`"]
>
> fexample1::"usage" = "Help example";
>
> Options[fexample1] = {a -> A, b -> B}
>
> Begin["`Private`"]
>
> fexample1[x_, opts___Rule] :=
>   (a + b) x /. {opts} /. Options[fexample1]
>
> End[]
>
> EndPackage[]
>
> (*Now I request the package Help*)
>
> ?"Test`Test1`*"
>
> (*They are shown not only the fexample1 help but the symbols used in
> Options are also shown. How can I prevend that these symbols (a, A, b,
> B} be shown.
>
> Other general question:
>
> When Options should be place inside of the private context?
> Thanks.
>
>
> Guillermo*)

```

• Prev by Date: Re: Sum question and general comment
• Next by Date: Re: Smalest enclosing circle
• Previous by thread: Re: Re: Re: Technical Publishing Made Easy with New Wolfram Publicon Software
• Next by thread: Re: Re: Package and options, subroutines Mathematica programming 3GL function procedure