Re: Question about Distribute
- To: mathgroup at smc.vnet.net
- Subject: [mg40742] Re: [mg40733] Question about Distribute
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 16 Apr 2003 01:34:34 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Distribute evaluates it's arguments and this is the cause of your
problems.
I suppose you have defined dist as follows:
dist[a_List, b_List] := Sqrt[(a - b).(a - b)]
With that you will get:
Distribute[dist[{{a, b}}, {{c, d}, {e, f}}], List]
Thread::tdlen:Objects of unequal length in {{a,b}}+{{-c,-d},{-e,-f}}
cannot \
be combined.
{Sqrt[({{a, b}} + {{-c, -d}, {-e, -f}}) . ({{a, b}} + {{-c, -d}, {-e,
-f}})]}
To prevent too early evaluation of dist use:
Distribute[Unevaluated[dist[{{a, b}}, {{c, d}, {e, f}}]], List]
Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/
{Sqrt[(a - c)^2 + (b - d)^2], Sqrt[(a - e)^2 + (b - f)^2]}
On Tuesday, April 15, 2003, at 04:59 pm, Ming Hsu wrote:
> Hi, I have a question about the distribute function. I was using it
> to find
> the euclidean distance between a point and a list of points. So I
> wrote the
> following function
>
>
> Distribute[f[{{2,1}}, points], List] /. f -> Dist
>
> where Dist is norm[point1-point2]
>
> My question is that why is it when I write Distribute[Dist[{{2,1}},
> points],
> List], mathematica complains about the first list is too short, but
> when I
> write it with the generic function f, it works.
>
> Thanks.
>
> Ming
>
>
>
>
>