-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Given a (periodic) function
After doing some search through the code, I don't think a convolution operator has been implemented in ApproxFun, though as a complete newbie, tbh, I am quite lost in the code. I could imagine a convolution was implemented as least implicitly, because I guess it is used for multiplying two functions over any Fourier space.
I managed to implement and explicit convolution for two functions on a Laurent() space. This is convenient, as the convolution basically just amounts to multiplying the coefficients of both functions:
#assume that f and g are Laurent over the same domain
function convolution_approxfun(f,g)
x0=first(ApproxFunBase.domain(f))
x1=last(ApproxFunBase.domain(f))
L=x1-x0
#fourier index of the n'th coefficient
fourier_index = [if mod(a,2)==1 div(a-1,2) else -div(a,2) end for a=1:ncoefficients(f)]
return Fun(Laurent(ApproxFunBase.domain(f)),f.coefficients.*g.coefficients.*L.*exp.(-2*pi*1im/L.*fourier_index*x0))
end
It works, but it is of course not very flexible code (Note the extra phase has to be added in case the interval starts at
The reason I need to implement the convolution operator is that I would like to solve some linear equation that contains a convolution operator. So the above explicit implementation is not enough for me, I need to implement an operator that I can add and multiply to other operators.
From what I understand about the functionality of ApproxFun.jl I think a good implementation would look something like this:
- Using a conversion operator to convert a function on any periodic domain to the canonical domain with the canonical space (I think its Fourier()) on it.
- Implementing a convolution operator on this canonical space, which is just multiplying the coefficients
- Using a conversion operator to convert the function back to the original domain/space
I have the feeling all of these steps could be very easy to implement, but I am lacking the detailed understanding of how ApproxFun.jl works in the background. I would be great if someone could help me with that: How do I implement a custom operator in general? How do I take care of the conversion properly?
PS: In case others agree I would be great to add convolution operators to the general functionality of ApproxFun in the future. At least for me convolution operators appear frequently in scientific computing.