[Date Index]
[Thread Index]
[Author Index]
Re: Unexpected Behavior: SetDelayed versus Set
*To*: mathgroup at smc.vnet.net
*Subject*: [mg120334] Re: Unexpected Behavior: SetDelayed versus Set
*From*: DrMajorBob <btreat1 at austin.rr.com>
*Date*: Tue, 19 Jul 2011 06:56:58 -0400 (EDT)
*References*: <201107181013.GAA26867@smc.vnet.net>
*Reply-to*: drmajorbob at yahoo.com
If we solve the quadratic equation:
Solve[a x^2 + b x + c == 0, x]
{{x -> (-b - Sqrt[b^2 - 4 a c])/(
2 a)}, {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}}
We get two solutions, but neither is correct -- or even defined -- if a ==
0, and neither is Real if b^2 - 4 a c < 0.
If b^2 - 4 a c == 0, there is only ONE solution, not two.
So, it's normal for Solve to return solutions that are WRONG for some
values of the parameters, and it's normal for it to return more general
solutions than can exist for a SPECIFIC set of parameter values. Some
combination of these facts came to light in your situation.
To be more specific, consider:
eqn = ((l*q)/cLohm)^2 == q*(aLinQS[area] + bQuadQS[area]*q)
parameters = {l -> 485, q -> 1925*(10^-3)};
general = Solve[eqn, area];
tests = eqn /. general /. parameters;
tests // Length
Most@tests
Last@tests /. Equal -> Subtract // N
(10000000000 l^2 q^2)/59609409228369 ==
q ((887623 Sqrt[\[Pi]])/(54367300000 area^(3/2)) + (1507 q)/(
16310190 area^2))
4
{False, False, False}
-1.40119*10^-11
Solve found four general solutions, but three are WRONG for the specific l
and q you have chosen. The fourth appears to be correct, although applying
N (as I did) doesn't prove it.
Applying Simplify or FullSimplify, as in
Last@tests /. Equal -> Subtract // Simplify
might prove it... but it is VERY slow, and I didn't wait for success or
failure.
When you insert values for l and q BEFORE solving, Solve has more
information to work with, hence it avoids spurious "solutions" that don't
solve the equation.
(*
The same is true for the quadratic equation. If we insert a -> 0 before
using Solve:
Solve[a x^2 + b x + c == 0 /. a -> 0, x]
{{x -> -(c/b)}}
Or, if the discriminant is zero, we get two identical solutions:
Solve[a x^2 + b x + c == 0 /. c -> b^2/(4 a), x]
{{x -> -(b/(2 a))}, {x -> -(b/(2 a))}}
Why didn't we get just one solution? I think it's because the root is
doubled, with zero derivative as well as value.
*)
Back to your problem,
specific = Solve[eqn /. parameters, area];
specific // N
{{area -> 0.00153505}}
eqn /. specific /. parameters /. Equal -> Subtract // N
{-7.78755*10^-12}
The specific solution appears to be the same as the last general solution:
(area /. First@specific) - (area /. Last@general) /. parameters // N
3.28335*10^-17
and Simplify can prove it:
(area /. First@specific) - (area /. Last@general) /.
parameters // Simplify
0
But equality is NOT visually obvious:
(area /. First@specific) - (area /. Last@general) /.
parameters // LeafCount
520
Bobby
On Mon, 18 Jul 2011 05:13:00 -0500, blamm64 <blamm64 at charter.net> wrote:
> Group,
>
> Please consider the following:
>
> gc = 3217*(10^-2)*12;
> orificeCD=65*(10^-2);
> kTorificeL=1/(orificeCD^2);
> reyTorifice=12;
> cLohm=(117*(10^-4))*1714*(385*(10^-2));
> nuStd=19*155*(10^-5); rhoStd=3014*(10^-5);
>
> aLinQS[area_]:=(kTorificeL*reyTorifice*nuStd*rhoStd)/
> (2*area*2*Sqrt[area/Pi]*gc);
>
> bQuadQS[area_]:=(kTorificeL*rhoStd)/(2*gc*area^2);
>
> Clear[taSD,taS,area,l,q];
>
> taSD[l_,q_] := area/.Solve[((l*q)/cLohm)^2==q*(aLinQS[area]
> +bQuadQS[area]*q),area];
>
> taS[l_,q_] = area/.Solve[((l*q)/cLohm)^2==q*(aLinQS[area]
> +bQuadQS[area]*q),area];
>
> {Dimensions[taSD[l,q]],Dimensions[taS[l,q]]}
> {{4},{4}}
>
> lm=485;qm=1925*(10^-3);
>
> N[taSD[lm,qm]]//InputForm
>
> {0.0015350502096417261}
>
> N[taS[lm,qm]]//InputForm
>
> {-0.0015301809337073798 - 4.86928826122106*^-6*I,
> -0.0015301809337073798 + 4.86928826122106*^-6*I,
> 0.0015253116577730662, 0.0015350502096416934}
>
> Now, this is really unexpected to me, especially in light of the of
> the Dimensions result where Symbols are substituted in the rhs of both
> definitions.
>
> For some unknown to me reason the SetDelayed definition returns the
> last member of the solution set when the rhs of the SetDelayed
> definition has numerial values for <l> and <q>.
>
> Obviously, again, I am missing something; but this time whatever it is
> I am missing has me gasping for air.
>
> -Brian L.
>
--
DrMajorBob at yahoo.com
Prev by Date:
**Re: 2 problems!**
Next by Date:
**Re: remarks on significance arithmetic implementation [Was: Re: Numerical accuracy/precision - this is a bug or a feature?]**
Previous by thread:
**Re: Unexpected Behavior: SetDelayed versus Set**
Next by thread:
**Re: Unexpected Behavior: SetDelayed versus Set**
| |