Skip to the content.

Differential Equation Solver

Members
Eve Zeng · Chau Vu · Dualeh² · Sultan Aldawodi

Abstract Physics‐informed neural networks (PINNs) offer a mesh‐free, data‐efficient approach to obtaining approximate solutions of ordinary differential equations (ODEs) by embedding the governing equations directly into the loss function of a neural network. In this project, we compare three distinct PINN implementations for solving benchmark ODEs: (i) a from‐scratch fully connected network coded in plain Python, (ii) a Keras‐based PINN leveraging TensorFlow’s high‐level APIs, and (iii) a DeepXDE model utilizing its specialized automatic differentiation and domain-decomposition features. These models were trained to solve simple ODEs, and their results were compared. The Keras and DeepXDE models performed with high accuracy, though the construction of the network needs to be modified with initial conditions to accommodate different scenarios. Still, these networks and their results demonstrate the reliable use of PINNs to solve ordinary differential equations and have a promising future in tackling complex partial differential equations with no analytical solutions.
Introduction ODEs (ordinary differential equations) are an important way of modeling the world in different fields such as economics, biology, and physics. For example, the physics of fluid dynamics is governed by the Navier–Stokes partial differential equations. Having accurate solutions to these equations gives power in analyzing complex systems. Our project focuses on testing a branch of neural network formalism called PINN (Physics‐informed neural networks) in its ability to solve differential equations, such that these equations produce simple and accurate results for difficult problems. Some of the hardest differential equations cannot be analytically solved, so having a reliable approximate solution from a neural network can help build complex models and systems. Our project tests three different kinds of PINNs, starting with a simple, made-from-scratch model using a fully connected neural network, then a Keras PINN via TensorFlow, and finally a DeepXDE model. Our tests on simple ODEs show promising signs for tackling more complex PDEs in future work.
Ethics Discussion Our project seeks to go beyond academic research by making our findings accessible through an interactive web interface, ensuring that anyone can use the program upon publishing our results. We understand there is the risk of students misusing this program in ways that violate school policies, such as cheating and plagiarism, but the applicability of this program in helping students learn and understand differential equations outweighs the chances of misuse, as it provides a learning opportunity for people who may not have access to advanced calculators.
Related Work Prior research has explored various methods for solving ODEs using neural networks. Some studies introduced PINNs to solve first- and second-order ODEs, highlighting their usefulness in physics simulations and their ability to incorporate physical laws directly into the model’s structure[^1]. Other studies expanded on this method by modifying the loss function to include the differential equation itself, allowing the model to learn to satisfy the equation rather than simply fit example data points[^2]. MathWorks presented a different strategy, using neural networks to produce closed-form approximations of ODE solutions, supported by a training process that involves generating data, defining the network, and customizing the loss function[^3]. Additionally, researchers have applied similar techniques to Partial Differential Equations (PDEs), training models on randomly sampled space and time points to approximate solutions where no analytical answers exist[^4]. Together, these works show the versatility and potential of neural networks in solving both ODEs and PDEs, laying the groundwork for our own project.
Methods The primary software we use to implement the PINN is TensorFlow and Keras. We will train three PINNs: a manually-built neural network, a Keras-based PINN using automatic differentiation, and a DeepXDE library that automates the setup and training of the neural network. The hand-built network is built using the Dense and Input layers from Keras, with the Adam optimizer used to minimize the loss function, which combines the residual of the differential equation with the error from the initial or boundary conditions. For the dataset, we constructed training data by sampling from various ODEs. For example, for the first-order ODE, such as \[ \frac{dy}{dx} + y = 0, \] the exact solution \[ y(x) = e^{-x} \]
Discussion We are creating our own data set, with methods provided by torchdiffeq, and trained our PINN with these specifically generated data set. We are implementing this PINN network to train three different data sets, corresponding to three different types of differential equations, based on these tests. We will also create a graph visualization to show how well our neural network’s predictions align with the ground truth solutions of the differential equation during the training process. After training these Neural Networks, we will again generate another set of data by similar methods, and test each of these three networks on their accuracy. We will compare our base type differential equation to the literature results, expecting to perform less accurately due to less data. We will also compare the accuracy between each type of NN, and decipher the potential reasons that one does better or worse. In the future, we would spend more time to figure out how to generalize our neural network to more types of equations.

Results

  1. PINNs built by hand (Non-Keras or XDE):
    • We found that this version is significantly less accurate than others because:
      • In our loss function, instead of using tf.GradientTape(u, t) like the Keras version, we use a finite‐difference stencil dNN ≈ (g(x+ε) − g(x)) / ε, which is slower, less stable, and inherently unreliable. Accuracy critically depends on choosing an optimal ( \epsilon ); if it’s too large, you miss details, and if it’s too small, floating-point noise dominates.
      • We’re not using tf.keras.Sequential, a model that has been developed and optimized for these tasks. Instead, we manually define our weights/biases and tf.matmul calls, which might be slower and more error-prone during training.
    • For this model, our loss function is designed to use a predefined ( f(x) ) function, which limits the model to solving equations that involve only ( x ). As a result, the model is less flexible because it cannot handle ODEs that include both ( x ) and ( y ) or other variable interactions.

  1. Keras PINNs:
    • The Keras package has existing functions that provides existing and established NN models. We used the sequential model provided by the Keras package. This model did well with our given example of a Sine wave, the original function and the NN approximation matched each other almost perfectly. However, problems arise when we try other equations that are not periodic. It is hard to normalize the equation when it goes to infinity, but not normalizing it could risk other problems to the activation function blowing up or going to zero. Thus, this is a problem that needs to be addressed for a better model of training all kinds of differential equation NN, not just the periodic ones.

Keras Loss Curve Keras Prediction vs Ground Truth

  1. DeepXDE PINNs: DeepXDE output for Sin(2pit):

DeepXDE Loss Curve Deep XDE Prediction vs Ground Truth

Conclusion/Future Work This project opens up opportunities for potential future work. One key direction we are focusing on is creating better models that can approximate higher-order equations and more complex systems. Another potential feature, given more time, would be to experiment with developing a combined model trained on the results from these individual models, capable of determining which model best fits the function type we are approximating. Additionally, we would like to create a web-based version of our models to showcase our results and more effectively communicate the differences between them.
Reflection In terms of research, specifically in the field of neural networks, our team learned a lot about PINNs, not only on how to implement these models, but also to compare and contrast their performances. We also trained our skills in finding literature, trying out sample codes, and refactoring these open-source model for our project’s goals. In addition to that, we also learned how to work in a group, plan tasks for everyone, and reprioritize as needed.
References 1. Amini, S., Hashemi, A., Azizi, A., & Ebrahimi, H. (2023). *Solving Differential Equations with Deep Learning: A Beginner’s Guide*. arXiv:2302.12260. <https://arxiv.org/abs/2302.12260> 2. Zang, Y., Bao, G., Ye, X., & Zhou, H. (2020). *Weak Adversarial Networks for High‑Dimensional Partial Differential Equations*. **Neurocomputing**, 399, 305‑315. <https://www.sciencedirect.com/science/article/abs/pii/S0925231220301909> 3. MathWorks. *Solve ODEs Using a Neural Network.* <https://www.mathworks.com/help/deeplearning/ug/solve-odes-using-a-neural-network.html> 4. Raissi, M., Perdikaris, P., & Karniadakis, G. E. (2019). *Physics‑Informed Neural Networks: A Deep Learning Framework for Solving Forward and Inverse Problems Involving Non‑linear PDEs*. **Journal of Computational Physics**, 378, 686‑707. <https://www.sciencedirect.com/science/article/pii/S0021999118305527> 5. *DeepXDE documentation.* <https://deepxde.readthedocs.io/en/latest/> 6. *Keras Model API.* <https://keras.io/api/models/model/> 7. *Hand‑built PINN Colab example.* <https://colab.research.google.com/drive/12ztGwxR1TK8Ka6H3bOsSt57kB71ieQ-W?usp=sharing> 8. *Keras & DeepXDE comparison Colab.* <https://colab.research.google.com/drive/1L1EmfOFFnoXfCF8YwNxkCflEV0gAScqx?usp=sharing>