Skip to content

Adding supporting code for blog post #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified phiml-blog-supporting-code/FNO/FNO_nonlinear_pendulum.mlx
Binary file not shown.
6 changes: 3 additions & 3 deletions phiml-blog-supporting-code/FNO/fourierLayer.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function layer = fourierLayer(tWidth,numModes,args)
function layer = fourierLayer(numModes,tWidth,args)

arguments
tWidth
numModes
tWidth
args.Name = ""
end
name = args.Name;
Expand All @@ -11,7 +11,7 @@

layers = [
identityLayer(Name="in")
spectralConvolution1dLayer(tWidth,numModes,Name="specConv")
spectralConvolution1dLayer(numModes,tWidth,Name="specConv")
additionLayer(2,Name="add")];

net = addLayers(net,layers);
Expand Down
4 changes: 2 additions & 2 deletions phiml-blog-supporting-code/FNO/spectralConvolution1dLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end

methods
function this = spectralConvolution1dLayer(outChannels,numModes,args)
function this = spectralConvolution1dLayer(numModes,outChannels,args)
% spectralConvolution1dLayer 1-D Spectral Convolution Layer
%
% layer = spectralConvolution1dLayer(outChannels, numModes)
Expand All @@ -34,8 +34,8 @@
% default value is [].

arguments
outChannels (1,1) double
numModes (1,1) double
outChannels (1,1) double
args.Name {mustBeTextScalar} = "spectralConv1d"
args.Weights = []
end
Expand Down
Binary file modified phiml-blog-supporting-code/HNN/HNN_nonlinear_pendulum.mlx
Binary file not shown.
12 changes: 7 additions & 5 deletions phiml-blog-supporting-code/PINN/solveNonlinearPendulum.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function sol = solveNonlinearPendulum(tspan,omega0,thetaDot0)
F = ode;
F.ODEFcn = @(t,x) [x(2); -omega0^2.*sin(x(1))];
F.InitialValue = [0; thetaDot0];
F.Solver = "ode45";
sol = solve(F,tspan);

F = ode;
F.ODEFcn = @(t,x) [x(2); -omega0^2.*sin(x(1))];
F.InitialValue = [0; thetaDot0];
F.Solver = "ode45";
sol = solve(F,tspan);

end
4 changes: 2 additions & 2 deletions phiml-blog-supporting-code/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Physics Informed Machine Learning Methods and Implementation supporting code
This repository provides examples demonstrating a variety of Physics-Informed Machine Learning (PhiML) techniques, applied to a simple pendulum system. The examples provided here are discussed in detail in the accompanying blog post "Physics-Informed Machine Learning: Methods and Implementation".
This collection provides examples demonstrating a variety of Physics-Informed Machine Learning (PhiML) techniques, applied to a simple pendulum system. The examples provided here are discussed in detail in the accompanying blog post "Physics-Informed Machine Learning: Methods and Implementation".

![hippo](https://www.mathworks.com/help/examples/symbolic/win64/SimulateThePhysicsOfAPendulumsPeriodicSwingExample_10.gif)

The techniques described for the pendulum are categorized by their primary objectives:
- **Modeling complex systems from data**
1. **Neural Ordinary Differential Equation**: learns underlying dynamics $f$ in the differential equation $\frac{d \mathbf{x}}{d t} = f(\mathbf{x},\mathbf{u})$ using a neural network.
2. **Neural State-Space**: learns both the system dynamics $f$ and the measurement function $g$ in the state-space model $\frac{d \mathbf{x}}{dt} = f(\mathbf{x},\mathbf{u}), \mathbf{y}=g(\mathbf{x},\mathbf{u})$ using neural networks. Not shown in this repository, but illustrated in the documentation example [Neural State-Space Model of Simple Pendulum System](https://www.mathworks.com/help/ident/ug/training-a-neural-state-space-model-for-a-simple-pendulum-system.html).
3. **Universal Differential Equation**: combines known dynamics $g$ with unknown dynamics $h$, e.g. $\frac{d\mathbf{x}}{dt} = f(\mathbf{x},\mathbf{u}) = g(\mathbf{x},\mathbf{u}) + h(\mathbf{x},\mathbf{u})$, learning the unknown part using a neural network.
3. **Universal Differential Equation**: combines known dynamics $g$ with unknown dynamics $h$, for example $\frac{d\mathbf{x}}{dt} = f(\mathbf{x},\mathbf{u}) = g(\mathbf{x},\mathbf{u}) + h(\mathbf{x},\mathbf{u})$, learning the unknown part $h$ using a neural network.
4. **Hamiltonian Neural Network**: learns the system's Hamiltonian $\mathcal{H}$, and accounts for energy conservation by enforcing Hamilton's equations $\frac{dq}{dt} = \frac{\partial \mathcal{H}}{\partial p}, \frac{dp}{dt} = -\frac{\partial \mathcal{H}}{\partial q}$.
- **Discovering governing equations from data:**
1. **SINDy (Sparse Identification of Nonlinear Dynamics)**: learns a mathematical representation of the system dynamics $f$ by performing sparse regression on a library of candidate functions.
Expand Down