[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*: [mg104428] Re: 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:52:53 -0500 (EST)
*Reply-to*: "Nasser M. Abbasi" <nma at 12000.org>
ref (me)
>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]
>
ps.After I posted the above, I noticed an extra {} inside all the matrix
elements in the result, this below is a version of the above which removes
these {}. Those got in due to the use of the line
r[[i,j]] = r[[i,j]] + A[[i,ii]] /@ {B[[ii,j]]}
where I had to use {} around B above, else Mathematica will complain but
this caused each entry inside to have those extra {}.
So below I remove them back when done with this line.
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}];
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]]}
];
r[[i, j]] = First[r[[i, j]]];
}
]
]
MatrixForm[r]
--Nasser
Prev by Date:
**How do I get Mathematica to Simplify this to 1?**
Next by Date:
**Multiply 2 matrices where one contains differential operators with one that contains functions of x and y**
Previous by thread:
**How do I get Mathematica to Simplify this to 1?**
Next by thread:
**Multiply 2 matrices where one contains differential operators with one that contains functions of x and y**
| |