[Date Index]
[Thread Index]
[Author Index]
Re: questions about delayed expression.
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19884] Re: [mg19862] questions about delayed expression.
*From*: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
*Date*: Sun, 19 Sep 1999 18:47:34 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
The answer to the first question is easy. You need to use
Inter[c_] = Interval[{sola[[1]], solb[[1]]}]
and not :=. If you use := the right hand side is not evaluated until you
evaluate Int[.3] but then of course Mathematica treats the c on the right
hand side just as a symbol and does not substitute 0.3 for it.
I can't think of any significantly simpler way of doing what you are asking
about in your second question. The following approach is an alternative but
is not really preferable.
In[1]:=
a[x_] := x + 4
In[2]:=
b[x_] := -3 x + 8
In[3]:=
sola = Roots[a[x] == c, x][[2]];
In[4]:=
solb = Roots[b[x] == c, x][[2]];
In[5]:=
Inter[c_] = Interval[{sola, solb}] ;
In[6]:=
Inter[0.3]
Out[6]=
Interval[{-3.7, 2.56667}]
In[7]:=
Inter[0.4]
Out[7]=
Interval[{-3.6, 2.53333}]
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp
----------
>From: d8442803 at student.nsysu.edu.tw (Wen-Feng Hsiao)
>To: mathgroup at smc.vnet.net
>Subject: [mg19884] [mg19862] questions about delayed expression.
>Date: Sun, Sep 19, 1999, 2:20 PM
>
> Hi,
>
> 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.
>
Prev by Date:
**Fast List-Selection**
Next by Date:
**Re: questions about delayed expression.**
Previous by thread:
**Re: questions about delayed expression.**
Next by thread:
**Re: questions about delayed expression.**
| |