MathGroup Archive 2003

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

Search the Archive

RE: Replace Function & Application!!!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38784] RE: [mg38774] Replace Function & Application!!!
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 12 Jan 2003 06:17:08 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Ashraf,

If you are new to Mathematica and plan to make regular use of it, then I
strongly recommend that you work through all the relevant parts of Part I of
the Mathematica Book. I would actually type in the examples and make certain
they work for you. That will answer a lot of questions you are likely to
have and save you time in the long run.

The Z has no special meaning in Mathematica. It is just a symbol that you
choose to store the solution value for r.

Here is a more detailed set of statements.

Solve[MS == P*(K*Y + S*r), r]
soln = %[[1,1]]
r /. %
z = %

which gives the series of output statements...

{{r -> -((-MS + K*P*Y)/(P*S))}}
r -> -((-MS + K*P*Y)/(P*S))
-((-MS + K*P*Y)/(P*S))
-((-MS + K*P*Y)/(P*S))

z has been set to the last output value. % means the output from the
previous statement.

Solve returns its result as a list of replacement rules. Since you are
allowed to solve a set of equations for a set of variables, each solution is
a list of replacement rules for all the solved variables.

Since, in your case, there was only one solution and one variable, the
second statement picks out the replacement rule itself.

The third statement uses the replacement rule to substitute for r. {"/." is
the shortcut entry for ReplaceAll.)

In the forth statement we set z to that value. But generally I wouldn't do
that. If you do, you can no longer use z as a symbolic variable. You might
later get into trouble if you forget to Clear z. As long as you have soln
you can substitute the solution for r whenever you want. For example, you
can easily evaluate the following expression.

a + b r + Sin[r]
% /. soln

a + b r + Sin[r]
a - (b*(-MS + K*P*Y))/(P*S) - Sin[(-MS + K*P*Y)/(P*S)]

I hope that helps some.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: Ashraf El Ansary [mailto:Elansary at btopenworld.com]
To: mathgroup at smc.vnet.net

Dear all thanks for your previous repoonse. Since I'm very new to
Mathematica, I was wondering what Replace[] function means in the following
case!!

Soln=Solve[MS==P*(K*Y+S*r),r]
Z=ReplaceAll[r,Soln[[1]]]

I know that first expression yields to

r->-(-MS+K P Y)/PS
while the second gives

-(-MS+K P Y)/PS . But what does Z actually means (i.e replacing r with first
part of itself) because if my input is Soln[[1]],  I will get r->-(-MS+K P
Y)/PS

so why when I input Z=ReplaceAll[r,Soln[[1]]] , r-> is eliminated from the
output



Thanx!!







  • Prev by Date: Re: Numerical description of a contour
  • Next by Date: Re: RE: RE: Multiplelistplot question
  • Previous by thread: Replace Function & Application!!!
  • Next by thread: FileNameDialog