MathGroup Archive 2006

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

Search the Archive

Re: How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63798] Re: [mg63755] How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 14 Jan 2006 02:33:14 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Young-Jin,

xlist = {x1, x2, x3, x4, x5};
ylist = {y1, y2, y3, y4, y5};

Transpose[{xlist, ylist}]
{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {x5, y5}}

Yes, you can have more than one statement in the definition of a function,
although I am not certain exactly what you are thinking of. Here is a sample
routine that has a usage message, an associated error message and a routine
that has more than one statement.

CompleteTheSquare::usage =
    "CompleteTheSquare[expr, var:x] returns expr as a perfect square plus a
constant. If the variable is not x, it must be supplied as the second
argument.";

CompleteTheSquare::notquad = "`1` is not a quadratic expression in `2`.";

CompleteTheSquare[expr_, var_:x] :=
  Module[{a, b, c},
   If[Exponent[expr, var] != 2,
     Message[CompleteTheSquare::notquad, expr, var];
      Return[]];
   {c, b, a} = CoefficientList[expr, var];
   a*(var + b/(2*a))^2 + c - b^2/(4*a)]

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

From: youngjin.michael at gmail.com [mailto:youngjin.michael at gmail.com]
To: mathgroup at smc.vnet.net


Hello,

I would like to know how to create a table format data such as {{x1,
y1}, {x2, y2}, ..., {xn, yn}} from
{x1, x2, ..., xn} and {y1, y2, ..., yn}.

I also would like to know if a user-defined function in Mathematica can
have more than one statements in its body.

Thanks in advance.

Young-Jin



  • Prev by Date: Re: data extraction question
  • Next by Date: Re: data extraction question
  • Previous by thread: Re: How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}
  • Next by thread: Pattern Matching: Keep those summands not depending on x