[Date Index]
[Thread Index]
[Author Index]
Re: Multiply 2 matrices where one contains differential operators with one that contains functions of x and y
*To*: mathgroup at smc.vnet.net
*Subject*: [mg104457] Re: [mg104417] Multiply 2 matrices where one contains differential operators with one that contains functions of x and y
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sun, 1 Nov 2009 03:58:58 -0500 (EST)
*References*: <20091029225146.K51SM.569239.imail@eastrmwml30> <200910310650.BAA13104@smc.vnet.net>
On 31 Oct 2009, at 15:50, Nasser M. Abbasi wrote:
> 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
>
>
Probably the easiest way is to use Inner, which is a generalisation of
Dot, replacing Times with the obsolete but still sometimes useful
function Compose:
Inner[Compose, {{D[#1, x] & , 0 & }, {0 & , D[#1, y] & },
{D[#1, y] & , D[#1, x] & }}, {{x*y, x^3*y, 3*x + y^2}, {2*x,
x^4*y, y^2}}, Plus]
{{y, 3*x^2*y, 3}, {0, x^4, 2*y},
{x + 2, 4*y*x^3 + x^3, 2*y}}
If you do not like to use a no-longer documented function you can
replace it by #1[#2]&.
Andrzej Kozlowski
Prev by Date:
**DateListBarChart / Ticks in BarChart**
Next by Date:
**Re: How do I get Mathematica to Simplify this to 1?**
Previous by thread:
**Re: Multiply 2 matrices where one contains differential operators with one that contains functions of x and y**
Next by thread:
**Re: Multiply 2 matrices where one contains differential operators with one that contains functions of x and y**
| |