Search   Memberlist   Usergroups
 Page 1 of 1 [2 Posts]
Author Message
mariano.suarezalvarez@gma

Joined: 28 Apr 2006
Posts: 58

Posted: Sat Jul 01, 2006 8:43 pm    Post subject: Re: mathematica command for linearity

robert wrote:
 Quote: if I type in mathematica f[x_+y_,z_]:=f[x_,z_]+f[y_,z_] then when I type f[a+b,c] I get f[a,c]+f[b,c]. But then when I type f[a+b+d,c] I get f[a+b+d,c]=f[a+b+d,c] and not f[a,c]+f[b,c]+f[d,c]. How can I teach mathematica to do that without typing a formula like the one at the beginning?

I sually use something like the following to inform Mma
that something is linear or multilinear:

ScalarQ[x_?NumberQ] := True;
MakeLinear[f_] := Block[{},
f[x_Plus] := f/@x;
f[c_?ScalarQ] := c f[1] /; c =!= 1;
f[c_?ScalarQ x_] := c f[x];
];
MakeMultilinear[f_] := Block[{},
f[x___,y_Plus,z___] := f[x,#,z]& /@ y;
f[x___,c_?ScalarQ y_,z___] := c f[x,y,z];
f[x___,c_?ScalarQ,z___] := c f[x,1,z] /; c =!= 1;
];

For example, after those definitions, you can say:

MakeLinear[F];
F[3 x + 5 y];

and you should get

3 F[x] + 5 F[y];

If you want to make something a scalar, you have
to be explicit: for example, if you want things like
a[1], a[2] and so on to be treated as scalars, and thus
take out of (multi)linear things, you say:

ScalarQ[a[_Integer]] := True

Then

T[a[4] x]

evaluates to

a[4] T[x]­

In general, these definitions alone are not good enough,
and I always end up tweaking things so that things are
more usable. Also, the patterns used above are not
general enough to cover all cases...

HTH,

-- m
robert1129
science forum beginner

Joined: 11 Jun 2006
Posts: 3

Posted: Sat Jul 01, 2006 8:04 pm    Post subject: mathematica command for linearity

if I type in mathematica
f[x_+y_,z_]:=f[x_,z_]+f[y_,z_]
then when I type f[a+b,c] I get f[a,c]+f[b,c].
But then when I type f[a+b+d,c] I get f[a+b+d,c]=f[a+b+d,c] and not
f[a,c]+f[b,c]+f[d,c].
How can I teach mathematica to do that without typing a formula like the one
at the beginning?

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Page 1 of 1 [2 Posts]
 The time now is Sun Nov 18, 2018 4:03 pm | All times are GMT
 Jump to: Select a forum-------------------Forum index|___Science and Technology    |___Math    |   |___Research    |   |___num-analysis    |   |___Symbolic    |   |___Combinatorics    |   |___Probability    |   |   |___Prediction    |   |       |   |___Undergraduate    |   |___Recreational    |       |___Physics    |   |___Research    |   |___New Theories    |   |___Acoustics    |   |___Electromagnetics    |   |___Strings    |   |___Particle    |   |___Fusion    |   |___Relativity    |       |___Chem    |   |___Analytical    |   |___Electrochem    |   |   |___Battery    |   |       |   |___Coatings    |       |___Engineering        |___Control        |___Mechanics        |___Chemical

 Topic Author Forum Replies Last Post Similar Topics mathematica: how to feed Solve output into Select? double d Math 12 Mon Jul 17, 2006 10:36 pm Eliminating multiple roots in mathematica's "Solve" function double d Symbolic 4 Sat Jul 15, 2006 11:49 am A web browser interface to Mathematica Dave (from the UK) Recreational 3 Fri Jul 07, 2006 9:41 am Mathematica code for an exponential sum graph Dave L. Renfro Math 2 Wed Jun 07, 2006 10:10 pm calling mathematica's FindRoot function from an external ... peregrine_falcon12@hotmai Math 0 Tue Jun 06, 2006 8:00 pm