Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc-example-files
Path: blob/master/sage/interact/LinearAlgebra/discreteFourier.sagews
Views: 1120
import scipy.fftpack as Fourier @interact def discrete_fourier(f = input_box(default=sum([sin(k*x) for k in range(1,5,2)])), scale = slider(.1,20,.1,5)): pbegin = -float(pi)*scale pend = float(pi)*scale html("<h3>Function plot and its discrete Fourier transform</h3>") show(plot(f, (x,pbegin, pend), plot_points = 512), figsize = [4,3]) f_vals = [f(x=ind) for ind in srange(pbegin, pend,(pend-pbegin)/512.0)] my_fft = Fourier.fft(f_vals) show(list_plot([abs(i) for i in my_fft], plotjoined=True), figsize = [4,3])
Interact: please open in CoCalc