Q:

IFFT to find sin(x^2)?

I want to use an inverse FFT to calculate inverse Fourier Transforms.  I find that I can readily do so with square integrable functions but not with distributions.  
First I set up a wavenumber vector k and a spatial coordinate x,
clear;

nx = 2^10;
L = 20;
dx = L/nx;
x = [0:nx-1]' * dx - L/2;

k = zeros(nx,1);
k(1:nx/2+1) = 2*[0:nx/2]/nx;
k(nx:-1:nx/2+2) = -k(2:nx/2);
k = k*pi/dx ;

Next I verify that everything works for two examples: the unit boxcar function and sech:
% boxcar

Ghat = sin( k/2 )  ./ (k/2);
Ghat(1) = 1;
Gi = ifft(Ghat) / dx ;
Gi = ifftshift(Gi);
figure; plot(x,Gi);

% sech( x )

Ghat = pi*sech( pi*k /2 );
Gi = ifft(Ghat) / dx ;
Gi = ifftshift(Gi);
figure; plot(x,Gi,'o'); hold on;
analytical = sech(x);
plot(x,analytical,'-');

Those both look fine... 
This is where things stop working:
% sin(x^2)

Ghat = -sqrt(pi)*sin( (k.^2-pi)/4 );
Gi = ifft(Ghat) / dx ;
Gi = ifftshift(Gi);
analytical = sin(x.^2);
figure;
plot(x,analytical,'-'); hold on;
plot(x,Gi,'o');

You will notice that the calculated values look nothing like the intended function.
I don't know why this wont work.  The only thing that I notice on Wikipedia is that sin(x^2) is a distribution and therefore not square integrable.  Is this the source of my problems?  Is there a solution?

A:

I'll give an example in python, should be easy to translate to Matlab.
import numpy as np
import matplotlib.pyplot as p
%matplotlib inline

dt=0.01
time = np.arange(0,10,dt) # 10 secs, sampled at 10 ms, so nyquist is 100 Hz
f=3 # hz
dat= np.sin(2*np.pi* f*time)

p.figure(figsize=(10,5))
p.subplot(221)
p.plot(time,dat)
p.subplot(222)
freqs = np.fft.fftfreq(len(time),d=dt)
#print(freqs)
spec=np.fft.fft(dat)
p.plot( freqs,np.abs(spec)  );

f=0.5
dat2= np.sin(2*np.pi* f*time**2)
p.subplot(223)
p.plot(time,dat2)
p.subplot(224)
p.plot( freqs,np.abs(np.fft.fft(dat2))  );

On the left the time-behaviour of the sine and the sine with squared argument (effectively you have a linear frequency change, an upchirp.  You could think of one x as the time, the other incorporated into your frequency, which is now rising linearly with time. In the spectrum (showing positive and neg frequency as FFT is defined as complex FT) you can see that the frequency of the sine wave is stable , whereas the sin(x**2) sweeps a range of frequencies. 
It always helps to plot things. With the sin(x**2) you could easily violate the Nyquist theorem if the argument rises too fast , leading to undersampling in the time -domain (left) and aliasing the frequency domain (right). This is not shown, just try with a higher base frequency. 

