MathGroup Archive 2006

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

Search the Archive

Re: using a previous result

  • To: mathgroup at
  • Subject: [mg67354] Re: [mg67324] using a previous result
  • From: "Chris Chiasson" <chris at>
  • Date: Mon, 19 Jun 2006 00:01:25 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

I wrote you two solutions that demonstrate a lot you might want to
learn about Mathematica.

The first is the way a person would normally code the solution. It has
several features. Functional notation (q[1] vs q1) is used so that
formulas can be written once and then applied multiple times via Map
(/@). Patterns are used to enable application of automatic rules
created by Set (=) and SetDelayed (:=) to different expressions
(eqn[1] for instance). Set after SetDelayed causes the value of
certain computations to be remembered (eqn[1] for instance), instead
of recomputed for each call. The result of the Solve command is also a
set of rules (Rule or ->) which may be used with ReplaceAll (/.), but
they are not used automatically like Set or SetDelayed.

The second solution shows how Mathematica will parse (due to order of
operations) the infix (/@ = := /. ->) and postfix ( [[1]] ) operator
forms in the first solution.

As a side note:
Multiple clicks of the mouse on brackets, operators, function names,
etc will greatly help you see how Mathematica parses expressions. This
technique is also good for reading long outputs.

q[1]=a+b p[1]+g p[2]
q[2]=c+d p[2]+e p[1]
profit[i_]=p[i] q[i]


On 6/18/06, ridley_david at <ridley_david at> wrote:
> Once I've solved a system of equations, I would like to use the
> previous results in future equations. If my output is {{p1->x,p2->y}}
> how do I assign those values as p1star and p2star so I can reuse them?
> Thank you,
> David
> For example:
> q1=a+b p1 +g p2;q2 = c+d p2 + e p1;profit1=p1 q1;profit2=p2 q2;
> FullSimplify[Solve[{D[profit1,p1]==0,D[profit2,p2]==0},{p1,p2}]]


  • Prev by Date: Re: matrix substitution--> Gell-Mann su(3) as a real 6by6 matrix group by substitution
  • Next by Date: Sturm-Liouville (eigenvalue/eigenfunction) problems
  • Previous by thread: using a previous result
  • Next by thread: Re: using a previous result