       Re: Forgets Variables?

• To: mathgroup at smc.vnet.net
• Subject: [mg97221] Re: [mg97175] Forgets Variables?
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Sun, 8 Mar 2009 05:53:14 -0500 (EST)
• References: <200903070738.CAA16926@smc.vnet.net>

```I can't get the first statement to execute (in the time I'm willing to
wait). If you gave us the values of maxX, eqTime, v, lifetime27SA, et
cetera, we'd waste a lot less time guessing what your problem might be.

If you want help, ALWAYS start us off where you are. Don't make us
flounder around where you've already been. Because, of course, why should
we?

That said, I'd start by simplifying until the code is understandable, at
which point the error will reveal itself. For instance, this:

If[v*(tsum - lifetime35S - eqTime) < 4000,
v*(tsum - lifetime35S - eqTime), 4000]

is equivalent to the simpler (and faster)

Min[v*(tsum - lifetime35S - eqTime), 4000]

Similarly, this expression:

If[v*(tsum - eqTime) < 4000, Max[v*(tsum - eqTime), 0], 4000]

is equivalent to

Max[0, Min[v*(tsum - eqTime), 4000]]

Next, it's easy to see that

If[v*(tsum2 - eqTime) < 4000,
Sum[Max[v*(tsum - eqTime), 0], {tsum, tsum2 - lifetime27SANTC + 1,
tsum2}],
Sum[Max[0, Min[v*(tsum - eqTime), 4000]], {tsum,
tsum2 - lifetime27SANTC + 1, tsum2}]]

is equivalent to

Clear[q]
q[ts_] := v*(ts - eqTime);
If[q@tsum2 < 4000,
Sum[Max[q@tsum, 0], {tsum, tsum2 - lifetime27SANTC + 1, tsum2}],
Sum[Max[0, Min[q@tsum, 4000]], {tsum, tsum2 - lifetime27SANTC + 1,
tsum2}]]

and that's equivalent to (since the Sums have the same limits):

Clear[q]
q[ts_] := v*(ts - eqTime);
Sum[If[q@tsum2 < 4000, Max[q@tsum, 0],
Max[0, Min[q@tsum, 4000]]], {tsum, tsum2 - lifetime27SANTC + 1,
tsum2}]

Similarly, the first If statement:

If[v*(tsum2 - lifetime35S - eqTime) < 4000,
Sum[Max[v*(tsum - lifetime35S - eqTime), 0], {tsum,
tsum2 - lifetime27SA + 1, tsum2}],
Sum[Min[v*(tsum - lifetime35S - eqTime), 4000], {tsum,
tsum2 - lifetime27SA + 1, tsum2}]]

is equivalent to

Clear[q]
q[ts_] := v*(ts - lifetime35S - eqTime);
Sum[If[q@tsum2 < 4000, Max[q@tsum, 0], Min[q@tsum, 4000]], {tsum,
tsum2 - lifetime27SA + 1, tsum2}]

Combining both tricks into one reduces the original expression to:

Clear[q]
q[life_][ts_] := v (ts - life - eqTime)
callNormValue =
60/maxX Sum[
tsum2 - lifetime27SA + 1, tsum2}]*(1 - P) +
Sum[If[q@tsum2 < 4000, Max[q@tsum, 0],
Max[0, Min[q@tsum, 4000]]], {tsum,
tsum2 - lifetime27SANTC + 1, tsum2}]*P, {tsum2, 60, t2, 60}];

That still won't evaluate without values for all the parameters, but
you're the only one that knows those, or even knows what ranges they might
lie in.

One trick you MIGHT pull, however, is this:

Clear[q]
q[life_][ts_] := v (ts - life - eqTime)
callNormValue =
60/maxX sum[
tsum2 - lifetime27SA + 1, tsum2}]*(1 - P) +
sum[If[q@tsum2 < 4000, Max[q@tsum, 0],
Max[0, Min[q@tsum, 4000]]], {tsum,
tsum2 - lifetime27SANTC + 1, tsum2}]*P, {tsum2, 60, t2, 60}];

(Now the statement executes.)

callNormValue /. {lifetime35S -> 17, P -> 0.7, t2 -> maxX, sum -> Sum}

(The other parameters still need values, but those could be added to the
rule list.)

Bobby

On Sat, 07 Mar 2009 01:38:46 -0600, Ktota <NuKtoBi at gmail.com> wrote:

> Hi there,
>
> i have the following procedure:
>
> callNormValue = (Sum[
>      If[v*(tsum2 - lifetime35S - eqTime) < 4000,
>         Sum[Max[v*(tsum - lifetime35S - eqTime), 0], {tsum,
>           tsum2 - lifetime27SA + 1, tsum2, 1}],
>         Sum[If[v*(tsum - lifetime35S - eqTime) < 4000,
>           v*(tsum - lifetime35S - eqTime), 4000], {tsum,
>           tsum2 - lifetime27SA + 1, tsum2, 1}]]*(1 - P) +
>       If[v*(tsum2 - eqTime) < 4000,
>         Sum[Max[v*(tsum - eqTime), 0], {tsum,
>           tsum2 - lifetime27SANTC + 1, tsum2, 1}],
>         Sum[If[v*(tsum - eqTime) < 4000, Max[v*(tsum - eqTime), 0],
>           4000], {tsum, tsum2 - lifetime27SANTC + 1, tsum2, 1}]]*
>        P, {tsum2, 60, t2, 60}])/(maxX/60);
>
> i call it with:
> callNormValue /. {lifetime35S -> 17, P -> 0.7, t2 -> maxX}
>
> it gives me a proper result, but as soon i change t2 to maxX in the
> first expression (where i do the sums) it doesn't evaluate the the
> procedure anymore (maxX has a global value already set). I have
> actually quite a lot of trouble to hand over values to this
> procedure.. and i have no idea why it doesn't work.
>
> (for except lifetime35S,P and t2 all the variables have a set value)
>
> thank you,
>
>  Ktota
>
>

--
DrMajorBob at bigfoot.com

```

• Prev by Date: Re: Mathematica 7.0.1.0 and some General Comments
• Next by Date: Re: Version 7.0.1 bug with initial Palette positions
• Previous by thread: Forgets Variables?
• Next by thread: Re: Forgets Variables?