# Solving differential equation using FFT: dealing with zero frequencies

To get started using spectral methods to solve differential equations I am currently using Matlab and its FFT library.

I have successfully approximated a first derivative of a function using the following Matlab code(based on this):

a = 0; %left end of the domain
b = 1; %right end of the domain
L = b-a; %length of the domain
N = 8; %Number of points
dx = L/N;
x = a + dx*(0:N-1);
k = 2*pi/L*[0:N/2-1, 0, -N/2+1:-1];

%% Exact solution
u = -4 * x.^2 + 4 * x;
du = -8 * x + 4;

%% Approximate solution
fftu = fft(u);
dffft = 1i*k.*fftu;
du_appr = ifft(dffft);

%% Plot
plot(x, du_appr)
hold on
plot(x, du)
legend('Approximate solution', 'Exact solution')


This works well for increasing N.

However, now imagine I would like to solve the differential equation:

$u_x = f(x)$

Where:

$f(x) = -8x + 4$

I would expect we can use the same idea but now inverted:

fftdu = fft(du);
u_h = fftdu./(1i*k);
u_appr = ifft(u_h);


As the frequency vector $k$ contains zeros this does not lead to a valid solution.

I am aware that normally the $0^{th}$ frequency bin represents the average of the signal, but I don't know how I could use that to solve my problem.

My question is therefore: How does one solve a simple differential equation using FFT?

All help is greatly appreciated.

• If the derivative of u wrt x is known, then which part of u is unknown? Which part or aspect of a function is lost when differentiating? If you differentiate $a+bx+cx^2$ and then integrate again, what can you say about $a,b$ and $c$? – mathreadler Oct 2 '17 at 12:58
• Do you mean that $a$ is left undefined by the process? For clarity, I am looking to solve more involved differential problems using FFT. However, I thought the problem of dividing by a zero frequency exists everywhere. And that it would therefore be most useful to ask the question for a simple equation. – Henk12 Oct 2 '17 at 13:39
• Yes $a$ is left undefined. So it is no drawback of the FFT but rather a property of differentiation and integration. One degree of freedom is gained. Which is why differential equations sometimes have boundary or initial conditions, because they would be impossible to solve uniquely otherwise. – mathreadler Oct 2 '17 at 13:46