MathGroup Archive 2006

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

Search the Archive

Re: Evaluate, /., {{...}}, etc.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70740] Re: Evaluate, /., {{...}}, etc.
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 25 Oct 2006 01:40:07 -0400 (EDT)
  • References: <ehkc9c$hqr$1@smc.vnet.net>


Hi Misha,

I think you are fooling yourself.

But first how braces and Replace work:

a+b/.a->a1 is the same as a+b/.{a->a1} the braces make more sense if we 

have more than one rule, e.g.: a+b/.{a->a1,b->b1}

a+b/.{{a->a1,b->b1},{a->a2,b->b2}} gives a list of 2 results, one for 

{a->a1,b->b1} and one for {a->a2,b->b2}



r1[x1_]:=Evaluate[x1/.{{x1 -> 5 -  x2/2}}]

Because of the double barces, this defines a function that returns a 

list with 1 element, probably not what you want.

r2[x1_]:=Evaluate[x1/.{x1 -> 10 - 2*x2}]

defines exactly what you want. You must have made a mistake.



Daniel



misha wrote:

> I'm having trouble figuring out how either Evaluate works or /. works 

> (with the logical understanding of "or"), as well as the asymmetric 

> appearance of curly brackets {} in what appears to me to be analogous 

> conditions.

> 

> In the example below, I expect r1[x1_]:=Evaluate[x1/.solution1] to 

> produce a function r1 as a function of x1 from the equation provided by 

> solution1.  Similar for r2.  I notice that solution1 is {{x1 -> 5 - 

> x2/2}}, whereas solution2 is {x1 -> 10 - 2*x2}.  Why "->" instead of "=" 

> or "=="?  Why two curly brackets in the first case {{...}} and only one 

> in the second case {...}?

> 

> More important,

> 

> r1 produces what I expect,

> In[...]:= ?r1

> 	Global`r1

> 	r1[x2_]:={5 - x2/2}

> 

> while r2 does not.

> In[...]:=?r2

> 	Global'r2

> 	r2[x1_]:=x2

> 

> I would expect the following

> 

> r2[x1_]:=10-2*x2

> 

> (i.e., since this problem is symmetric, firm 1's "reaction function" 

> (r1) should be symmetric w.r.t. firm 2's "reaction function" (r2). 

> Again, why curly brackets in one case, but not in the other?

> 

> Here is the full example (from 

> http://library.wolfram.com/infocenter/MathSource/551/):

> 

> p1[x1_,x2_] := 10 - b1 x1 - c x2

> p2[x1_,x2_] := 10 - b2 x2 - c x1

> profit1[x1_,x2_] := Evaluate[p1[x1,x2]*x1]

> profit2[x1_,x2_] := Evaluate[p2[x1,x2]*x2]

> solution1=Solve[D[profit1[x1,x2],x1]==0,x1][[1]]

> solution2=Solve[D[profit2[x1,x2],x2]==0,x2][[1]]

> r1[x2_] := Evaluate[x1/.solution1]

> r2[x1_] := Evaluate[x2/.solution2]

> c=b1

> b1=b2=c=1

> isoprofitLines=ContourPlot[profit1[x1,x2],{x1,0,7},{x2,0,7},ContourShading->False]

> reactionCurves=ParametricPlot[{{r1[t],t},{t,r2[t]}},{t,0,7}]

> Show[isoprofitLines,reactionCurves]

> 



  • Prev by Date: "Declaring" a vector for NDSolve
  • Next by Date: Re: two questions
  • Previous by thread: Evaluate, /., {{...}}, etc.
  • Next by thread: Re: Evaluate, /., {{...}}, etc.