Multiply 2 matrices where one contains differential operators with one that contains functions of x and y
- To: mathgroup at smc.vnet.net
- Subject: [mg104417] Multiply 2 matrices where one contains differential operators with one that contains functions of x and y
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Sat, 31 Oct 2009 01:50:39 -0500 (EST)
- References: <20091029225146.K51SM.569239.imail@eastrmwml30>
- Reply-to: "Nasser M. Abbasi" <nma at 12000.org>
Hello,
Version 7
Lets say A is a 3 by 2 matrix, which contains differential operators in some
entries and 0 in all other entries, as in
A= { { d/dx , 0 } , {0 , d/dy } , { d/dy , d/dx } }
And I want to multiply the above with say a 2 by 3 matrix whose entries are
functions of x and y as in
B = {{x*y, x^3*y, 3*x + y^2}, {2*x, x^4*y, y^2}}
I'd like to somehow be able to do A.B, but ofcourse here I can't, as I need
to "apply" the operator on each function as the matrix multiplication is
being carried out.
I tried to somehow integrate applying the operators in A into the matrix
multiplication of A by B, but could not find a short "functional" way.
So I ended up solving this by doing the matrix multiplication by hand using
for loops (oh no) so that I can 'get inside' the loop and be able to apply
the operator to each entry. This is my solution:
A = {{D[#1, x] & , 0 & }, {0 & , D[#1, y] & }, {D[#1, y] & , D[#1, x] & }}
B = {{x*y, x^3*y, 3*x + y^2}, {2*x, x^4*y, y^2}}
{rowsA, colsA} = Dimensions[A];
{rowsB, colsB} = Dimensions[B];
r = Table[0, {rowsA}, {colsB}]; (*where the result of A.B goes *)
For[i = 1, i <= rowsA, i++,
For[j = 1, j <= colsB, j++,
For[ii = 1, ii <= rowsB, ii++,
r[[i,j]] = r[[i,j]] + A[[i,ii]] /@ {B[[ii,j]]}
]
]
]
MatrixForm[r]
The above work, but I am sure a Mathematica expert here can come up with a
true functional solution or by using some other Mathematica function which I
overlooked to do the above in a more elegent way.
--Nasser