PINN Loss Function Generation with Symbolic Math

Generate Deep Learning Toolbox code for use in a physics-informed neural network (PINN) directly from a symbolically defined PDE or ODE.
405 Downloads
Updated 8 Dec 2025

View License

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, as well as solve inverse and parametric problems.
Setup
Ensure that the files pde2PINNLossFunction.m and ode2PINNLossFunction.m are on your path.
MathWorks Products (https://www.mathworks.com)
Requires MATLAB® R2024a or newer
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, RLC_ODE.mlx, RLC_ODE_Inverse.mlx, and Parametric_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
  • RLC_ODE_Inverse.mlx: use a PINN to estimate circuit parameters in an RLC circuit
  • Parametric_ODE.mlx: use a PINN to estimate the solution to a parametric ODE given a new value of the parameter
License
The license is available in the License.txt file in this repository.
Community Support
Copyright 2025 The MathWorks, Inc.

Cite As

Mae Markowski (2026). 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 Linux
Tags Add Tags
Version Published Release Notes
1.1.1

Adding support for inverse and parametric problems.

1.1.0

Added functionality for inverse problems (parameter estimation from data) and parametric problems.

1.0.0