PINN Loss Function Generation with Symbolic Math
Version 1.0.0 (1.58 MB) by
Mae
Generate Deep Learning Toolbox code for use in a physics-informed neural network (PINN) directly from a symbolically defined PDE or ODE.
PINN Loss Function Generation with Symbolic Math
Physics-Informed Neural Networks (PINNs) can approximate solutions to ordinary differential equations (ODEs) and partial differential equations (PDEs) by embedding the differential equations into the loss function of the network to guide the learning process. In this way, PINNs can provide more physically consistent predictions than purely data-driven methods. Further, they provide meshfree alternatives to traditional numerical methods.
Central to the PINN loss function is the physics-informed loss term, which evaluates the residual of the differential equation at interior collocation points in the domain. The derivatives are usually computed via automatic differentiation (AD).
This repository provides helper functions which automatically generate the physics-informed loss term from symbollically defined ODEs and PDEs. This physics-informed term can then be used to train PINNs to approximate solutions to PDEs and ODEs.
Setup
Ensure that the files pde2PINNLossFunction.m and ode2PINNLossFunction.m are on your path.
Requires MATLAB® R2024a or newer
- Symbolic Math Toolbox™
- Deep Learning Toolbox™
- Statistics and Machine Learning Toolbox™ (only for training data generation)
Getting Started
- Check out the examples in Start_here.mlx to learn how to define differential equations symbolically and how to use the repository functions to generate the physics-informed loss functions from these symbolic equations.
- For examples which walk through the entire PINN workflow, see Burgers_PDE.mlx, Poisson_PDE.mlx, and RLC_ODE.mlx.
- For an advanced workflow which may offer improved performance through less network forward passes, see NoForward_example.m.
Workflow Examples
- Burgers_PDE.mlx: use a PINN to approximate the solution to 1D Burgers' equation. This extends the documentation example Solve Partial Differential Equations Using Deep Learning to auto-generate the physics-informed loss term from symbolic Burgers' equation.
- Poisson_PDE.mlx: use a PINN to approximate the solution to 2D Poisson equation. This extends the documentation example Solve Poisson Equation on Unit Disk Using Physics-Informed Neural Networks to auto-generate the physics-informed loss term from symbolic Poisson equation.
- RLC_ODE.mlx: use a PINN to approximate the 2nd order ODE arising from an RLC circuit
License
The license is available in the License.txt file in this repository.
Community Support
Copyright 2024 The MathWorks, Inc.
Cite As
Mae (2025). PINN Loss Function Generation with Symbolic Math (https://www.mathworks.com/matlabcentral/fileexchange/172049-pinn-loss-function-generation-with-symbolic-math), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
pinn-loss-generation-with-symbolic-math-main
pinn-loss-generation-with-symbolic-math-main
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |