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
Post by y***@gmail.comHello,
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 ***@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
Post by y***@gmail.comHello,
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 ***@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