Re: What does & mean?
- To: mathgroup at smc.vnet.net
- Subject: [mg107090] Re: [mg107050] What does & mean?
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 2 Feb 2010 03:30:14 -0500 (EST)
- Reply-to: hanlonr at cox.net
Just decompose complex expressions and look at them one step at a time
A = {{4, -6}, {1, -1}};
X[t_] = {x[t], y[t]};
{X'[t], A.X[t]}
{{Derivative[1][x][t],
Derivative[1][y][t]},
{4*x[t] - 6*y[t], x[t] - y[t]}}
system = MapThread[#1 == #2 &, {X'[t], A.X[t]}]
{Derivative[1][x][t] ==
4*x[t] - 6*y[t],
Derivative[1][y][t] ==
x[t] - y[t]}
"&" indicates a pure function. Select "&" and hit F1 and the search results will include a link to Function. #1 == #2 & is shorthand for Function[#1 == #2]
system = MapThread[Function[#1 == #2], {X'[t], A.X[t]}]
{Derivative[1][x][t] ==
4*x[t] - 6*y[t],
Derivative[1][y][t] ==
x[t] - y[t]}
Or more explicitly
system = MapThread[Function[{x, y}, x == y], {X'[t], A.X[t]}]
{Derivative[1][x][t] ==
4*x[t] - 6*y[t],
Derivative[1][y][t] ==
x[t] - y[t]}
If you don't like MapThread
Transpose[{X'[t], A.X[t]}]
{{Derivative[1][x][t],
4*x[t] - 6*y[t]},
{Derivative[1][y][t],
x[t] - y[t]}}
system = Apply[Equal, Transpose[{X'[t], A.X[t]}], 1]
{Derivative[1][x][t] ==
4*x[t] - 6*y[t],
Derivative[1][y][t] ==
x[t] - y[t]}
Also, Apply[f, expr, 1] can be abbreviated f@@@expr
system = Equal @@@ Transpose[{X'[t], A.X[t]}]
{Derivative[1][x][t] ==
4*x[t] - 6*y[t],
Derivative[1][y][t] ==
x[t] - y[t]}
Bob Hanlon
---- Michael Knudsen <micknudsen at gmail.com> wrote:
=============
Hi,
I have recently bought Mathematica, and I have a really tough time
getting started. I'm reading the various documents found under
"Complete Documentation" at the Mathematica homepage, but it doesn't
feel like the right place to start.
For example, I'm now trying to solve some simple differential
equations, and the documentation provides the following example:
A = {{4, -6}, {1,-1}};
X[t_] = {x[t], y[t]};
system = MapThread[#1 == #2 &, {X'[t], A.X[t]}];
sol = DSolve[system, {x,y}, t]
However, there is no explanation of how & works here (and it isn't in
the MapThread documentation either). Where should one start reading in
order to understand basic constructs like this? This particular
example is really nasty, since & is generally ignored by search
engines.
Thanks,
Michael Knudsen