[Date Index]
[Thread Index]
[Author Index]
Re: questions about delayed expression.
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19906] Re: [mg19862] questions about delayed expression.
*From*: "Wolf, Hartmut" <hwolf at debis.com>
*Date*: Tue, 21 Sep 1999 02:22:44 -0400
*Organization*: debis Systemhaus
*References*: <199909190520.BAA10204@smc.vnet.net.>
*Sender*: owner-wri-mathgroup at wolfram.com
Wen-Feng Hsiao schrieb:
>
> The following is the process that I run in my notebook.
>
> In[1]:=
> a[x_] := x + 4
> b[x_] := -3 x + 8
>
> In[2]:=
> sola = x /. Solve[{a[x] == c}, x];
> solb = x /. Solve[{b[x] == c}, x];
>
> In[3]:=
> Inter[c_] := Interval[{sola[[1]], solb[[1]]}]
>
> In[4]:=
> Inter[.3]
> Inter[.4]
>
> Out[4]=
> \!\(Interval[{\(-4\) + c, \(8 - c\)\/3}]\)
>
> Out[5]=
> \!\(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
> solb[[1]].
>
> Please give me suggestions. Thanks for your help.
Dear Hsiao,
To question (1.) look at your definition of "Inter", it is SetDelayed
and doesn't contain the pattern variable c explicitly at the rhs. So
when you evaluate Inter[.4] then there is no c on the rhs to be
substituted into, and when -- _after_ that -- the rhs is being
evaluated, and c shows up then it hasn't got a value, esp. not 0.4! So
you end up with Out[5] (which is the same as Out[4]).
To get what you want, define
inter1[c_] = Interval[{sola[[1]], solb[[1]]}]
or
inter2[c_] := Evaluate[Interval[{sola[[1]], solb[[1]]}]]
There are still other methods to feed in the actual value of c (e.g. if
you definitely need the delayed evaluation of sola, solb, perhaps
because you happen to redefine them in course of your calculation), e.g.
inter3[cThis_] := Block[{c = cThis}, Interval[{sola[[1]], solb[[1]]}]]
In your case they all give
Interval[{-3.6, 2.53333}], and Interval[{-3.7, 2.56667}]
for 0.4 and 0.3 respectively.
For (2.) you could use (since you have exactly one solution in each
case, else you have to make a selection) e.g.
Interval[Flatten[x /. {Solve[{a[x] == c}, x], Solve[{b[x] == c}, x]},
1]]
but there are dozens of ways to arrive at that.
Kind regards, hw
Prev by Date:
**Re: Coordinate Transformations**
Next by Date:
**Re: Solving equations involving Ln function**
Previous by thread:
**questions about delayed expression.**
Next by thread:
**Re: questions about delayed expression.**
| |