.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/simple_pdes/pde_1d_expression.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_simple_pdes_pde_1d_expression.py: 1D problem - Using `PDE` class ============================== This example implements a PDE that is only defined in one dimension. Here, we chose the `Korteweg-de Vries equation `_, given by .. math:: \partial_t \phi = 6 \phi \partial_x \phi - \partial_x^3 \phi which we implement using the :class:`~pde.pdes.pde.PDE`. .. GENERATED FROM PYTHON SOURCE LINES 14-30 .. image-sg:: /examples_gallery/simple_pdes/images/sphx_glr_pde_1d_expression_001.png :alt: pde 1d expression :srcset: /examples_gallery/simple_pdes/images/sphx_glr_pde_1d_expression_001.png :class: sphx-glr-single-img .. code-block:: Python from math import pi from pde import PDE, CartesianGrid, MemoryStorage, ScalarField, plot_kymograph # initialize the equation and the space eq = PDE({"φ": "6 * φ * d_dx(φ) - laplace(d_dx(φ))"}) grid = CartesianGrid([[0, 2 * pi]], [32], periodic=True) state = ScalarField.from_expression(grid, "sin(x)") # solve the equation and store the trajectory storage = MemoryStorage() eq.solve(state, t_range=3, solver="scipy", tracker=storage.tracker(0.1)) # plot the trajectory as a space-time plot plot_kymograph(storage) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 9.978 seconds) .. _sphx_glr_download_examples_gallery_simple_pdes_pde_1d_expression.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pde_1d_expression.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pde_1d_expression.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pde_1d_expression.zip `