MathGroup Archive 2002

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

Search the Archive

RE: Simple Concept I can't figure out! Making rules?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38084] RE: [mg38046] Simple Concept I can't figure out! Making rules?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 3 Dec 2002 04:29:00 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Stan,

I think it is a shame that any engineering college would frown upon using
Mathematica. If used correctly, it can only speed learning and give you a
lot more practice. It is also a shame that students can't come to college
already knowing the basics of Mathematica so they could concentrate on the
material to be learned. The argument that the student is supposed to be
learning methods and not use Mathematica's advanced automatic routines: one
can always skip the advanced routines and program Mathematica to do the
steps of the method to be learned.

Anyway, on to your question. You could do something like this...

xsol = Solve[2x - 1 == 0, x][[1, 1]]
answer = x /. xsol // N

which returns

x -> 1/2
0.5

answer
0.5

Look up ReplaceAll and Rule in Help. What I like to do is save xsol as a
rule and not store the x value in some variable answer, or in x itself. I
would also tend to stay with exact solutions as long as possible.  Then you
can use xsol and N something like this...

x^2 + Sin[x]
% /. xsol
% // N

which gives

x^2 + Sin[x]
1/4 + Sin[1/2]
0.729426

Remember that % means the previous output (in time) and when you use it for
statements within one cell it is completely unambiguous. /. is the shortcut
notation for ReplaceAll. So % /. xsol means to take the previous output, and
replace all occurrences of x using the rule xsol (which is x -> 1/2).

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

From: Stan [mailto:snarten at runbox.com]
To: mathgroup at smc.vnet.net

Even though it's frowned upon by the engineering college, i use
mathematica a lot of the stuff that would take pages of code in
another system. I have most basic functions and operations down, but I am
lacking one basic thing I need to do to be able to program more
problems successfully:

here is my problem:

Lets say you solve an equation using "Solve"

Solve[2x - 1 == 0, x] // N

{{x -> 0.5}}

How would I then use the result of "Solve" (0.5) and assign it to a
new variable, like "answer"  for further calculations?

I think it has something to do with /. and -> rules of some sort, but
I can't get this simple concept to work!

Thanks for the help.

-Stan



  • Prev by Date: Re: solving non-algebraic exponential equations
  • Next by Date: Re: copying cells in Mathematica 4.2
  • Previous by thread: Re: Simple Concept I can't figure out! Making rules?
  • Next by thread: Re: Simple Concept I can't figure out! Making rules?