Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14161

Re: "Programming With Mathematica" Exercise help

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: "Programming With Mathematica" Exercise help
Date 2013-04-12 06:15 +0000
Message-ID <kk88q6$c0l$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


On 4/11/13 at 4:13 AM, plank.in.sequim@gmail.com wrote:

>I'm loving Paul Wellin's book "Programming with Mathematica: An
>Introduction" and am trying to diligently do all the exercises.
>Most of them have answers in the back but I'm stuck on Section 4.2,
>Exercise 2 and there's no answer given.  It gives the following
>Mathematica code:

>z = 11; a = 9; z + 3 /. z -> a

>14

>So "z+3" is being evaluated to 14 and then the substitution has no
>effect. He asks how to "use the Hold function in the compound
>expression to obtain a value of 12".

If I wanted to evaluate an expression with z using a different
value than what had been assigned to it without reseting it, I
would use Block not Hold. That is:

In[1]:= z = 11;
a = 9;
Block[{z}, z + 3 /. z -> a]

Out[3]= 12

Likely there is a way to accomplish the same using Hold, but it
seems to me Block is more specifically designed for this type of task.

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: "Programming With Mathematica" Exercise help Bill Rowe <readnews@sbcglobal.net> - 2013-04-12 06:15 +0000
  Re: "Programming With Mathematica" Exercise help plank.in.sequim@gmail.com - 2013-04-14 00:36 +0000

csiph-web