RE: really simple question

• To: mathgroup at smc.vnet.net
• Subject: [mg71075] RE: [mg71038] really simple question
• From: "David Park" <djmp at earthlink.net>
• Date: Wed, 8 Nov 2006 06:12:34 -0500 (EST)

```I know many users do it but I would really hesitate before writing a
statement like a = 3. This gives a built-in value to a and you can no longer
use it as a symbol. Also, if you change it somewhere, say with a = 4, then
it may be easy to lose track of what it's current value is. Rather I would
use rules to hold the values of parameters and then substitute with the
rules whenever you want numeric values. Something like this...

parmvalues = {a -> 3, b -> 5, c -> Pi/4};

Then if you have a symbolic expression that involves the parameters you can
substitute as follows.

expr = a x + b x^2 + Cos[c];

expr /. parmvalues
1/Sqrt[2] + 3*x + 5*x^2

But, better yet, I might write the above expression with a pattern argument,
and subvalue patterns for the parameters.

f[a_, b_, c_][x_] := a x + b x^2 + Cos[c]

Then when I want it evaluated with specific values I would insert them into
the expression.

f[3, 5, Pi/4][x]
1/Sqrt[2] + 3*x + 5*x^2

or

f[3, 5, Pi/4][2]
26 + 1/Sqrt[2]

The object is to keep your expressions symbolic and general as long as
possible and don't assign or substitute numeric values until you absolutely
have to. The same thing goes for units - they should be part of the data and
not part of the symbolic expression.

data = {a -> 3 Meter, b -> 5 Second, c -> Pi/4};

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: xarnaudx at gmail.com [mailto:xarnaudx at gmail.com]
To: mathgroup at smc.vnet.net

when you type stuff in the input like:
In[1]: a = 3
and execute it, the result is shown in the output:
Out[1]: 3

since i do many different computations, i wish i had as output:
Out[1]: a = 3

(and not only 3 without the "a ="!)

where can i set the option to see which result is affected to what
variable by default?

```

• Prev by Date: Re: xvnc Mathematica menu fonts
• Next by Date: Re: General--Another Trigonometric Problem....NEED HELP
• Previous by thread: RE: really simple question
• Next by thread: Re: really simple question