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: [mg63789] Re: [mg63755] How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sat, 14 Jan 2006 02:32:48 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200601130948.EAA03554@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

For your first question, look up Transpose in the Help Browser.  You may 
combine separate x- and y- lists into a single {x,y} list like this:

    x = {1, 2, 3, 4};
    y = {10, 20, 30, 40};
    Transpose[{x, y}]
{{1, 10}, {2, 20}, {3, 30}, {4, 40}}


For your second question, look up CompoundExpression and Module in the 
Help Broswer.  User-defined functions can have as body any expression-- 
in particular, a "compound expression" consisting of individual 
expressions separated from one another by semi-colons.  For (a silly) 
example:

   myFunc[x_] := (a = x^2; a + 1)
   myFunc[3]
10

(The parentheses are needed in the definition of myFunc because, 
otherwise, the input line would be parsed to mean, "first, define 
myFunc[x_] by a = x^2 end; next, evaluate a + 1" and then evaluating the 
line would give result 1 + a and would define myFunc so that the value 
of myFunc[3] would be 9.)

Of course such a function definition, involving the symbol a, is a bad 
idea, since it will have the side-effect, when it is used, of assigning 
a value to a.  So most often a function definition "with more than one 
statement in its body" would be constructed by using Module (or perhaps 
one of the related constructs With or Block).

Look up CompoundExpression
youngjin.michael at gmail.com wrote:
 > 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
 >
 >

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

youngjin.michael at gmail.com wrote:
> 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
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: data extraction question
  • Next by Date: Re: Question about UpSet vs SetDelayed
  • Previous by thread: Re: How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}
  • Next by thread: Re: How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}