Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Why do these not work?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109712] Re: Why do these not work?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 13 May 2010 07:24:16 -0400 (EDT)

There was a problem with the earlier e-mail.

Clear[plane3];

plane3[p1_, p2_, p3_] :=
 Module[
  {x1, y1, z1, x2, y2, z2, x3, y3, z3, iden},
  {x1, y1, z1} = p1;
  {x2, y2, z2} = p2;
  {x3, y3, z3} = p3;
  1/Det[{p1, p2, p3}]*Det /@ {
     {{1, y1, z1}, {1, y2, z2}, {1, y3, z3}},
     {{x1, 1, z1}, {x2, 1, z2}, {x3, 1, z3}},
     {{x1, y1, 1}, {x2, y2, 1}, {x3, y3, 1}}}]

plane3[{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}] /.
 {x1 -> 1, y1 -> 0, 
  z1 -> 0, x2 -> 0, y2 -> 1, z2 -> 0, x3 -> 0, y3 -> 0, z3 -> 1}

{1,1,1}

The replacement must happen prior to the call to plane3

plane3[Sequence @@ ({q1, q2, q3} /.
    {q1 -> {1, 0, 0}, q2 -> {0, 1, 0}, 
     q3 -> {0, 0, 1}})]

{1,1,1}

Alternatively, prevent plane3 from evaluating unless (until) the arguments are proper.

Clear[plane3];

plane3[p1_?VectorQ, p2_?VectorQ, p3_?VectorQ] :=
 Module[
  {x1, y1, z1, x2, y2, z2, x3, y3, z3, iden},
  {x1, y1, z1} = p1;
  {x2, y2, z2} = p2;
  {x3, y3, z3} = p3;
  1/Det[{p1, p2, p3}]*Det /@ {
     {{1, y1, z1}, {1, y2, z2}, {1, y3, z3}},
     {{x1, 1, z1}, {x2, 1, z2}, {x3, 1, z3}},
     {{x1, y1, 1}, {x2, y2, 1}, {x3, y3, 1}}}]

plane3[{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}] /.
 {x1 -> 1, y1 -> 0, 
  z1 -> 0, x2 -> 0, y2 -> 1, z2 -> 0, x3 -> 0, y3 -> 0, z3 -> 1}

{1,1,1}

plane3[q1, q2, q3] /.
 {q1 -> {1, 0, 0}, q2 -> {0, 1, 0}, q3 -> {0, 0, 1}}

{1,1,1}


Bob Hanlon


=============

---- "S. B. Gray" <stevebg at ROADRUNNER.COM> wrote: 

=============
There is something about Mathematica which does not allow the first two calls to 
work, and I don't know why. Can anyone give me some guidance?

First, do I need all these things in the Module and is there a shorter 
way to "localize" them?

plane3[p1_,p2_,p3_] :=
  Module[{x1,y1,z1, x2,y2,z2, x3,y3,z3, iden},

   {x1, y1, z1} = p1;
   {x2, y2, z2} = p2;
   {x3, y3, z3} = p3;

   iden = 1/Det[{{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}}];
    (* Or 1/Det[{p1,p2,p3}] *)

    aa = iden*Det[{{ 1, y1, z1},{ 1, y2, z2},{ 1, y3, z3}}];
    bb = iden*Det[{{x1,  1, z1},{x2,  1, z2},{x3,  1, z3}}];
    cc = iden*Det[{{x1, y1,  1},{x2, y2,  1},{x3, y3,  1}}];
    Return[{aa, bb, cc}];     (* Plane: aa*x + bb*y + cc*z = 1 *)
   ]

This ReplaceAll gives the numeric answer I want:
plane3[{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}] /.
  {x1 -> 1, y1 -> 0, z1 -> 0,
   x2 -> 0, y2 -> 1, z2 -> 0,
   x3 -> 0, y3 -> 0, z3 -> 1}
{1,1,1}

This ReplaceAll does not work at all:
plane3[q1,q2,q3]/.{q1->{1,0,0},q2->{0,1,0},q3->{0,0,1}}

This ReplaceAll gives a symbolic answer that I do not want:
q1={x1,y1,z1}; q2={x2,y2,z2}; q3={x3,y3,z3};
plane3[q1,q2,q3]/.{q1->{1,0,0},q2->{0,1,0},q3->{0,0,1}}

What is the rule? I note in ReplaceAll x/.{{x->1},{x->3},{x->7}},
but I don't want one at a time.

Thank you for any tips.
Steve Gray




  • Prev by Date: Re: Part specification... is neither an integer nor a list of integers
  • Next by Date: Re: How to write reports and books in Mathematica
  • Previous by thread: Re: Why do these not work?
  • Next by thread: Re: Why do these not work?