MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Forgets Variables?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97315] Re: Forgets Variables?
  • From: Ktota <NuKtoBi at gmail.com>
  • Date: Tue, 10 Mar 2009 05:39:05 -0500 (EST)
  • References: <200903070738.CAA16926@smc.vnet.net> <gp0830$l48$1@smc.vnet.net>

Ok Raffy, your suggestion helped me a lot at least i could get a step
further. I would love to make functions out of some of my procedures,
nevertheless i get often "times .. or tag .. is protected" error. Well
that shouldn't matter to much as it should work just like this too. I
suspect that the problem is that I'm calling my callNormValue out of a
sum function ... and callNormValue consists of 2 other Sum functions.
Is it possible that the nested Sum functions might cause trouble?


there you see how i call callNormValue (with ReleaseHold.. as it
otherwise wouldn't work at al, model35S contains a statement
describing a mathematical modell) to normalize my model

sumfunc = Sum[
   (
     (model35S /. {t -> tsum5})/(ReleaseHold[
         callNormValue /. {lifetime35S -> 15,
           P -> 0.7}]) - (interpolatedExpData35S[tsum5])
     )^2
   , {tsum5, 60, 900, 60}];

execute the above statement with:
sumfunc /. {P -> 0.7, lifetime35S -> 15}

gives me a result...

so but to get the thing to work i need to have the values which i set
when i call sumfunc

therefore:

Sumfunc = Sum[
   (
     (model35S /. {t -> tsum5})/(ReleaseHold[
         callNormValue /. {lifetime35S -> lifetime35S,
           P -> P}]) - (interpolatedExpData35S[tsum5])
     )^2
   , {tsum5, 60, 900, 60}];

execute the above statement with:
sumfunc /. {P -> 0.7, lifetime35S -> 15}

but in this case i just get my not evaluated statement back

 maybe someone has something generally to say about that

 Ktota

On 9 Mrz., 06:02, Ktota <NuKt... at gmail.com> wrote:
> Thank you for your help Raffy and Bob, i'll try your suggestions and
> report here again. This model evolved over time.. i think i will have
> also to spend to optimize it as Bob suggests.. his suggestions are
> very nice... i'm busy learning Mathematica it seems to be a very
> helpfull tool ;).
>
>  Kind Regards,
>
>  Ktota
>
> On 8 Mrz., 10:53, DrMajorBob <btre... at austin.rr.com> wrote:
>
>
>
>
>
>
>
> > 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[
> >      Sum[If[q[lifetime35S]@tsum2 < 4000, Max[q[lifetime35S]@tsum, 0=
> ],
> >          Min[q[lifetime35S]@tsum, 4000]], {tsum,
> >          tsum2 - lifetime27SA + 1, tsum2}]*(1 - P) +
> >       Sum[If[q[0]@tsum2 < 4000, Max[q[0]@tsum, 0],
> >          Max[0, Min[q[0]@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 migh=
> t
> > lie in.
>
> > One trick you MIGHT pull, however, is this:
>
> > Clear[q]
> > q[life_][ts_] := v (ts - life - eqTime)
> > callNormValue =
> >    60/maxX sum[
> >      sum[If[q[lifetime35S]@tsum2 < 4000, Max[q[lifetime35S]@tsum, 0=
> ],
> >          Min[q[lifetime35S]@tsum, 4000]], {tsum,
> >          tsum2 - lifetime27SA + 1, tsum2}]*(1 - P) +
> >       sum[If[q[0]@tsum2 < 4000, Max[q[0]@tsum, 0],
> >          Max[0, Min[q[0]@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 <NuKt... 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
Ok, certainly i can rewrite my program... nevert

> > > 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
>
> > --
> > DrMajor... at bigfoot.com



  • Prev by Date: Re: Re: Mathematica 7.0.1.0 and some General Comments
  • Next by Date: Re: Quantum Mathematica sneak preview of commutator and operator
  • Previous by thread: Re: Forgets Variables?
  • Next by thread: Re: Forgets Variables?