Re: Defining Functions and Simplifying Solutions
- To: mathgroup at smc.vnet.net
- Subject: [mg90530] Re: Defining Functions and Simplifying Solutions
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 12 Jul 2008 05:30:38 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g56t8m$3pq$1@smc.vnet.net>
Locus wrote:
> 1. Is there a more handy way to define/use functions as compared to the following way (which works, but is complicated always typing the variable definitions):
>
> G[\[Alpha]1_Real, \[Alpha]2_Real, e1_Real,
> e2_Real] = \[Alpha]1*e1 + \[Alpha]2*e2
>
> v[G_Real] = a*G[\[Alpha]1, \[Alpha]2, e1, e2] + b
Sorry, but, first I do not understand what you mean, second I strongly
doubt that the above definitions work the way you expect.
G[\[Alpha]1_Real, \[Alpha]2_Real, e1_Real,
e2_Real] = \[Alpha]1*e1 + \[Alpha]2*e2;
v[G_Real] = a*G[\[Alpha]1, \[Alpha]2, e1, e2] + b;
Having evaluated
v[3.]
you get
b + a 3.[\[Alpha]1, \[Alpha]2, e1, e2]
that is v[3.] change the *head* of the function "G" into "3." which
apparently is not going to lead you anywhere ...
> 2. After several steps, I receive the following solution
>
> {{a -> (0. (e1 \[Beta]1 + e2 \[Beta]2 \[Lambda]))/(rA \[Tau]^2)}}
>
> which obviously equals zero. How can I 'force' Mathematica to display only 0 as result and not such a unnessecarily complicated expression? FullSimplify does not work here.
Note that "0." denotes a *machine-size* number, thus the value is zero
plus or minus some uncertainty on the numerical result. In other words,
although it might be a true zero, it can also be anything between zero
and plus or minus the granularity of hardware precision. And this
without counting any numerical, round-off, underflow, and the likes, errors.
On the other hand, all the others quantities are symbolic and by default
represent *exact* (i.e. *infinite* precision) values. Mathematica plays
it safe by not automatically upgrading the precision of "0." from
very-low to infinite.
Therefore you must tell Mathematica that "0." must be treated as (or is
really) zero, that is "0" without followed by a dot.
Among many other possibilities, you could try one of the following:
sol = {{a -> (0. (e1 \[Beta]1 +
e2 \[Beta]2 \[Lambda]))/(rA \[Tau]^2)}};
sol // Chop
sol /. 0. -> 0
sol // SetPrecision[#, Infinity] &
sol // Rationalize
{{a -> 0}}
{{a -> 0}}
{{a -> 0}}
{{a -> 0}}
Also, the following (short) tutorials might be worth reading:
http://reference.wolfram.com/mathematica/tutorial/TheUncertaintiesOfNumericalMathematics.html
http://reference.wolfram.com/mathematica/tutorial/NumericalFunctions.html
http://reference.wolfram.com/mathematica/tutorial/NumericalPrecision.html
http://reference.wolfram.com/mathematica/tutorial/NumbersOverview.html
Regards,
-- Jean-Marc