FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Forum index » Science and Technology » Math
mathematica command for linearity
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
mariano.suarezalvarez@gma
science forum addict


Joined: 28 Apr 2006
Posts: 58

PostPosted: Sat Jul 01, 2006 8:43 pm    Post subject: Re: mathematica command for linearity Reply with quote

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
Back to top
robert1129
science forum beginner


Joined: 11 Jun 2006
Posts: 3

PostPosted: Sat Jul 01, 2006 8:04 pm    Post subject: mathematica command for linearity Reply with 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?

thanks in advance.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Wed Sep 19, 2018 8:11 pm | All times are GMT
Forum index » Science and Technology » Math
Jump to:  

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

Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Electronics forum |  Medicine forum |  Unix/Linux blog |  Unix/Linux documentation |  Unix/Linux forums  |  send newsletters
 


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0230s ][ Queries: 20 (0.0040s) ][ GZIP on - Debug on ]