MathGroup Archive 1999

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

Search the Archive

Re: questions about delayed expression.

  • To: mathgroup at
  • Subject: [mg19891] Re: [mg19862] questions about delayed expression.
  • From: "David Park" <djmp at>
  • Date: Sun, 19 Sep 1999 18:47:38 -0400
  • Sender: owner-wri-mathgroup at

Wen-Feng Hsiao wrote:

>   The following is the process that I run in my notebook.
>a[x_] := x + 4
>b[x_] := -3 x + 8
>sola = x /. Solve[{a[x] == c}, x];
>solb = x /. Solve[{b[x] == c}, x];
>Inter[c_] := Interval[{sola[[1]], solb[[1]]}]
>\!\(Interval[{\(-4\) + c, \(8 - c\)\/3}]\)
>\!\(Interval[{\(-4\) + c, \(8 - c\)\/3}]\)
>My questions are:
>1. Why Inter[.3] and Inter[.4] cannot be evaluated? Their results should
>not be the same. This is not my intention.
>2. I don't know if there is any better way to extract the 'root(s)' from
>the output of 'Solve' command. The output form is {{x->root1}, {x-
>>root2}, ...{}}. If I use 'ReplaceAll'(/.) command, it will remain a list
>of solutions of x. It seems I can only use element operation to extract
>the root(s) from the solution list? In my case, I use sola[[1]] and
>Please give me suggestions. Thanks for your help.

There are two things that can help. First, you can pick off the two solutions by:

sola = x /. Solve[{a[x] == c}, x][[1,1]]
-4 + c

solb = x /. Solve[{b[x] == c}, x][[1,1]]
(8 - c)/3

Then, define Inter with immediate evaluation:

Inter[c_] = Interval[{sola, solb}]
Interval[{-4 + c, (8 - c)/3}]

To get Inter[c_] defined as a function of c, it is necessary to get c explicitly on
the right hand side. Then wherever c occurs, it is replaced by the argument as the
first step in evaluation. But with the delayed definition, there is no c there, so
the argument never gets substituted.

Interval[{-3.7, 2.56667}]

Interval[{-3.6, 2.53333}]

David Park
djmp at

  • Prev by Date: Re: Limits of multi-var. functions
  • Next by Date: Re: Re: F[f_,x_]:=f[x] ?
  • Previous by thread: Re: questions about delayed expression.
  • Next by thread: Re: questions about delayed expression.