0
votes

First off, I didn't know what to put as title, since the question is not easy to formulate shortly.

I need to convolve a matrix-valued function (k) with a vector-valued function (X), each of which is defined on R^3. I need to to this in MATLAB, so naturally I will do the discretized version. I plan on representing k and X by 5- and 4-dimensional arrays, respectively. This seems a bit heavy though. Do you know if there are any better ways to do it?

Instead of doing the convolution directly, I will go to Fourier space by fft'ing both k and X, pad with zeros, multiply them and then use ifft. That should produce the same result and run much, much faster.

My question here is whether there is any way to multiply these arrays/matrices easily? I.e. is there any way to do k(i,j,k,:,:)*X(i,j,k,:) for all i,j,k, without using three nested loops?

2

2 Answers

1
votes

Do you need to discretize? Matlab is perfectly capable of taking functions as input and output. For examples, you could define a convolution function:

>> convolve = @(fm,fv) @(x) fm(x) * fv(x); %fm matrix valued, fv vector valued

and define some matrix-valued and vector-valued functions (this assumes the input is a column vector)

>> f = @(x) [x x x];
>> g = @(x) cos(x);

now their convolution:

>> h = convolve(f,g);

and try applying it to a vector:

>> h([1;2;3])
ans =
   -0.8658
   -1.7317
   -2.5975

You get the same answer as if you did the operation manually:

>> f([1;2;3]) * g([1;2;3])
ans =
   -0.8658
   -1.7317
   -2.5975
0
votes

You perform element-by-element operation by using . together with the operator of choice. For example:

Element-by-element multiplication: .* 
Element-by-element division: ./

and so on... is that what you mean?