       Re: Making a LOOP (DO)

• To: mathgroup at smc.vnet.net
• Subject: [mg102291] Re: Making a LOOP (DO)
• From: pfalloon <pfalloon at gmail.com>
• Date: Tue, 4 Aug 2009 04:28:33 -0400 (EDT)
• References: <h56bjl\$bkh\$1@smc.vnet.net>

```On Aug 3, 7:45 pm, Youness Eaidgah <y.eaid... at gmail.com> wrote:
> Dear All,
>
> Based on the following table, I want to calculate the =93Total Expected Profit
> (TEP)=94. The retailer profit (REP) is a function of OR, D1, and p (which are
> known and described at the table) as well as R and P which are unknown.
>
> For calculating each cell of the table, I have the following formulas (the
> values of highlighted variables come from table. The values of variables
> highlighted in orange are unknown):
>
> REP=(100*DE*(1-R)+SI*20-P*OR)
>
> Where,
>
> DE=If[D1*<=*OR,D1,OR];
>
> SI=If[OR>=D1,OR-D1,0]
>
> *12000*
>
> *(OR)*
>
> *14000*
>
> *(OR)*
>
> 1st scenario
>
> *D1*
>
> 8000
>
> A=REP*p
>
> D=REP*p
>
> *p*
>
> 0.11
>
> 2nd scenario
>
> *D1*
>
> 10000
>
> B=REP*p
>
> E=REP*p
>
> *p*
>
> 0.11
>
> 3rd scenario
>
> *D1*
>
> 12000
>
> C=REP*p
>
> F=REP*p
>
> *p*
>
> 0.28
>
> Total Expected Profit (TEP)
>
> A+B+C
>
> D+E+F
>
> Therefore, to calculate the total expected profit (TEP), I need a loop that
> sum the value at each column. To do so, I made the following loop:
>
> Clear[REP,REP]
>
> Do[
>
>  DE=If[D1<=OR,D1,OR];
>
>  SI=If[OR>=D1,OR-D1,0];
>
>  REP[OR]=REP[OR]+((100*DE*(1-R)+SI*20-P*12000)*p),
>
> {OR,12000,14000,2000},
>
> {{D1,p},{8000,0.11},{10000,0.11},{12000,0.28}}];
>
>  {REP,REP}
>
> However, the loop does not work as expected. It might be because I
> introduced {D1, p} as a couple. But, I need to do that. I would be really
> grateful if you could help me out.
>
> Thank you,
>
> Youness

Well, the syntax doesn't allow it --- as even a fairly cursory perusal
of the documentation (and/or some experimentation) would verify. So,
you need to find another way.

One solution would be simply re-defining {D1, p} as, say, D1pPair, and
enclosing the values in a list will make it work:

Do[..., {D1pPair, {{x1,y1}, {x2,y2}, ...}}]

In the body of the Do loop, you would then replace D1 by D1pPair[],
and p by D1pPair[].

This will work, although almost certainly there is a much more compact
and elegant way to reformulate the entire calculation.

P.

```

• Prev by Date: Re: Multiplication of matrices
• Next by Date: Re: Noob Question re Setting Default Fonts
• Previous by thread: Making a LOOP (DO)
• Next by thread: Batteries {Was: Re: Hacking Wolfram|Alpha)