Discussion:
How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn} and {y1, ..., yn}
(too old to reply)
y***@gmail.com
2006-01-13 10:10:29 UTC
Permalink
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
albert
2006-01-14 08:10:33 UTC
Permalink
Hi,
Post by y***@gmail.com
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}.
l1={x1, x2, x3};
l2={y1, y2, y3};

Transpose[{l1,l2}]
Post by y***@gmail.com
I also would like to know if a user-defined function in Mathematica can
have more than one statements in its body.
yes. just seperate them with ';' . You might also want to look for
CompoundExpression in the Helpbrowser...

hth

albert
Jacob A. Siehler
2006-01-14 08:12:34 UTC
Permalink
Post by y***@gmail.com
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}.
Thread[List[{x1,x2,x3},{y1,y2,y3}]]

is an idiomatic one-liner.
J Siehler
2006-01-14 08:13:35 UTC
Permalink
Post by y***@gmail.com
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}.
{ {x1,x2,...,xn}, {y1,y2,...,yn} } //Transpose

may be the simplest.
Jean-Marc Gulliet
2006-01-14 08:14:36 UTC
Permalink
Post by y***@gmail.com
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
Hi Young-Jin,

*Transpose* will do what you want.

In[1]:=
xlist = {x1, x2, x3}
ylist = {y1, y2, y3}
Transpose[{xlist, ylist}]

Out[1]=
{x1, x2, x3}

Out[2]=
{y1, y2, y3}

Out[3]=
{{x1, y1}, {x2, y2}, {x3, y3}}

Best regards,
/J.M.
Jens-Peer Kuska
2006-01-14 08:20:41 UTC
Permalink
Hi,

a) Transpose[{{x1, x2, ..., xn},{y1, y2, ..., yn}}]
b) no but ther exist a single statement CompoundExpression[] that is
abbreviated by
the infix operator ";" and can hold any sequence of statements

Regards
Jens
Post by y***@gmail.com
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
Bob Hanlon
2006-01-14 08:21:42 UTC
Permalink
x={x1,x2,x3,x4};
y={y1,y2,y3,y4};

Thread[{x,y}]

{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}

Transpose[{x,y}]

{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}

f[a_,b_,c_,x_]:=Module[{t1,t2},
t1=a*x^2;
t2=b*x;
t1+t2+c];

f[a,b,c,z]

a*z^2 + b*z + c


Bob Hanlon
Subject: How to create {{x1,y1}, ..., {xn,yn}} data from {x1,...,xn}
and {y1, ..., yn}
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
Sseziwa Mukasa
2006-01-14 08:27:49 UTC
Permalink
Post by y***@gmail.com
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}.
Transpose[{{x1,x2,...},{y1,y2,...}}]
Post by y***@gmail.com
I also would like to know if a user-defined function in Mathematica
can
have more than one statements in its body.
Yes, use ; to form compound expresssions.

Regards,

Ssezi
Murray Eisenberg
2006-01-14 08:30:51 UTC
Permalink
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.com
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 ***@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.com
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 ***@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
David Park
2006-01-14 08:39:58 UTC
Permalink
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
***@earthlink.net
http://home.earthlink.net/~djmp/

From: ***@gmail.com [mailto:***@gmail.com]


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
Clifford Martin
2006-01-14 08:40:59 UTC
Permalink
Hi,

For example:
varx= { x1,x2,x3,x4}
yvar= { y1,y2,y3,y4}
usvar= Transpose[ { varx,yvar}]
{x1, x2, x3, x4}
{y1, y2, y3, y4}
{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}

Does this answer your question?

As far as compound statements in a function just use parentheses around the compound statements for example.

dffunc := (first statement;
second statement;
third statement;)

Good luck,

Cliff

"***@gmail.com" <***@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
g***@sarj.ca
2006-01-14 08:45:01 UTC
Permalink
Hi Young-jin,

On Friday, January 13, 2006 at 04:48 GMT -0500, Youngjin.Michael wrote:

<snip>
Post by y***@gmail.com
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}.
There are many ways, but the fastest is:
list1 = {x1,...,xn};
list2 = {y1,...,yn};
desiredlist = Transpose[{list1,list2}]
Post by y***@gmail.com
I also would like to know if a user-defined function in Mathematica can
have more than one statements in its body.
There are many ways. Check out Module[], Block[], Function[] or () to
enclose the statements. Remember, statements need to be separated by ;
when grouped together. For example:

myFunc[x_]:=Module[{y=x^2,z},
z = 2*y+5;
z/x]
Christopher Arthur
2006-01-15 10:55:17 UTC
Permalink
Hi Young-Jin,

Use the Transpose[] command to regroup your data---for example

if X is n x 2 list, i.e., {{x1,...,xn},{y1,...,yn}},
then transpose[X] is 2 x n list...

Cheers,

Chris Arthur
----- Original Message -----
From: <***@gmail.com>
Subject: How to create {{x1,y1}, ..., {xn,yn}} data from
{x1,...,xn} and {y1, ..., yn}
Post by y***@gmail.com
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
Loading...