Preprint
Article

This version is not peer-reviewed.

Physics-Informed Neural Networks for Solving Second-Order Boundary Value Problems: A Comparative Study with Fem and Finit Difference Methods

A peer-reviewed version of this preprint was published in:
Science Discovery Physics 2026, 1(2), 118-130. https://doi.org/10.11648/j.sdp.20260102.14

Submitted:

05 April 2026

Posted:

07 April 2026

You are already at the latest version

Abstract
Physics-Informed Neural Networks (PINNs) have emerged as a powerful paradigm for solving partial differential equations (PDEs) by embedding physical laws directly into the neural network training process. This paper presents a comprehensive comparative study of PINNs against traditional numerical methods—Finite Element Method (FEM) and Finite Difference (FD)—for solving second-order boundary value problems. We focus on the canonical problem u″(x)=e-x on the domain [0,1] with Dirichlet boundary conditions u(0)=1 and u(1)=e-1, which admits the exact analytical solution u(x)=e-x. The PINN architecture employs a trial solution formulation that automatically satisfies boundary conditions, utilizes automatic differentiation for computing derivatives, and leverages the L-BFGS optimizer with Sobol quasi-random collocation points. We provide rigorous mathematical derivations of the PINN loss function, trial solution construction, automatic differentiation chain rules, FEM weak formulation with stiffness matrix assembly, and FD central difference schemes. Numerical experiments demonstrate that PINNs achieve comparable accuracy to FEM and FD methods while offering mesh-free flexibility and the ability to incorporate physical constraints naturally. The relative L2 error for all three methods remains below 10-3, validating the effectiveness of physics-informed learning for boundary value problems. This work contributes to the growing body of evidence supporting PINNs as a viable alternative to classical numerical methods in computational physics and engineering.
Keywords: 
;  ;  ;  ;  ;  ;  

1. Introduction

The numerical solution of partial differential equations (PDEs) has been a cornerstone of computational science and engineering for decades. Traditional methods such as the Finite Element Method (FEM) and Finite Difference (FD) schemes have proven highly effective but often require significant domain expertise, mesh generation, and computational resources [1,2]. Recent advances in deep learning have introduced a paradigm shift through Physics-Informed Neural Networks (PINNs), first systematically developed by Raissi et al. [3,4]. PINNs embed the governing physical laws directly into the neural network loss function, enabling mesh-free, data-efficient solutions to forward and inverse PDE problems.
The fundamental innovation of PINNs lies in their ability to approximate PDE solutions by minimizing a composite loss function that penalizes violations of the governing equations, boundary conditions, and initial conditions [3]. Unlike traditional numerical methods that discretize the domain and solve large linear systems, PINNs leverage automatic differentiation to compute derivatives of the neural network output with respect to inputs, thereby evaluating PDE residuals at collocation points [5,6]. This approach has been successfully applied to diverse problems including fluid dynamics [7], solid mechanics [8], heat transfer [9], and multiphysics simulations [10].
Despite their promise, PINNs face several challenges. Training can be sensitive to hyperparameters, collocation point distribution, and network architecture [11,12]. The optimization landscape is often non-convex with multiple local minima, necessitating careful initialization and advanced optimization algorithms [13]. Furthermore, the accuracy and convergence properties of PINNs compared to well-established numerical methods remain an active area of research [2,14].
This paper addresses these questions through a rigorous comparative study of PINNs, FEM, and FD methods for a canonical second-order boundary value problem. We consider the ordinary differential equation:
u ″ ( x ) = e − x ,   x ∈ [ 0,1 ]
subject to Dirichlet boundary conditions:
u ( 0 ) = 1 ,   u ( 1 ) = e − 1
This problem admits the exact analytical solution u ( x ) = e − x , enabling precise quantification of numerical errors. The simplicity of the one-dimensional setting allows us to focus on the fundamental differences between methods without the complications of higher-dimensional geometry.
Our contributions are threefold:
  • Comprehensive Mathematical Derivations: We provide detailed derivations of the PINN trial solution formulation, automatic differentiation for computing second derivatives, loss function construction, FEM weak formulation with stiffness matrix assembly, and FD central difference schemes.
  • Implementation Details: We present a complete PINN implementation using a 3-layer feedforward network with 10 neurons per layer, sin activation functions, He initialization, Sobol quasi-random collocation points, and L-BFGS optimization.
  • Quantitative Comparison: We compare the accuracy, convergence, and computational characteristics of PINNs, FEM (50 elements), and FD (50 intervals) for the benchmark problem.
The remainder of this paper is organized as follows. Section 2 formulates the mathematical problem and establishes notation. Section 3 derives the three numerical methods in detail. Section 4 describes the neural network architecture. Section 5 outlines the training procedure. Section 6 presents numerical results and comparative analysis. Section 7 concludes with insights and future directions.

2. Mathematical Formulation

2.1. Problem Statement

We consider the second-order linear ordinary differential equation:
d 2 u d x 2 = e − x ,   x ∈ Ω = [ 0,1 ]
with Dirichlet boundary conditions:
u ( 0 ) = u 0 = 1 ,   u ( 1 ) = u 1 = e − 1
This is a two-point boundary value problem (BVP) that models various physical phenomena, including steady-state heat conduction with exponentially decaying source terms, beam deflection under distributed loads, and electrostatic potential distributions.

2.2. Exact Solution

The general solution to the homogeneous equation u ″ ( x ) = 0 is:
u h ( x ) = C 1 + C 2 x
For the particular solution, we seek u p ( x ) such that u p ″ ( x ) = e − x . By inspection or the method of undetermined coefficients, we find:
u p ( x ) = e − x
since:
d d x e − x = − e − x ,   d 2 d x 2 e − x = e − x
The general solution is:
u ( x ) = C 1 + C 2 x + e − x
Applying boundary conditions:
u ( 0 ) = C 1 + 1 = 1 ⟹ C 1 = 0
u ( 1 ) = C 2 + e − 1 = e − 1 ⟹ C 2 = 0
Therefore, the exact solution is:
u ( x ) = e − x
This closed-form solution serves as the ground truth for evaluating numerical methods.

2.3. Weak Formulation

For the FEM derivation, we require the weak (variational) formulation. Multiply the PDE by a test function v ∈ H 0 1 ( Ω ) (where H 0 1 denotes the Sobolev space of functions with square-integrable first derivatives and zero boundary values) and integrate over Ω :
∫ 0 1 u ″ ( x ) v ( x )   d x = ∫ 0 1 e − x v ( x )   d x
Integrating by parts on the left-hand side:
∫ 0 1 u ″ ( x ) v ( x )   d x = u ' ( x ) v ( x ) 0 1 − ∫ 0 1 u ' ( x ) v ' ( x )   d x
Since v ∈ H 0 1 ( Ω ) , we have v ( 0 ) = v ( 1 ) = 0 , so the boundary term vanishes:
− ∫ 0 1 u ' ( x ) v ' ( x )   d x = ∫ 0 1 e − x v ( x )   d x
Rearranging:
∫ 0 1 u ' ( x ) v ' ( x )   d x = − ∫ 0 1 e − x v ( x )   d x
This is the weak formulation: Find u ∈ H 1 ( Ω ) with u ( 0 ) = 1 and u ( 1 ) = e − 1 such that:
∫ 0 1 u ' ( x ) v ' ( x )   d x = − ∫ 0 1 e − x v ( x )   d x ,   ∀ v ∈ H 0 1 ( Ω )
This formulation is the foundation for the Finite Element Method.

3. Methodology

3.1. Physics-Informed Neural Networks (PINNs)

3.1.1. Neural Network Approximation

PINNs approximate the solution u ( x ) using a feedforward neural network N ( x ; θ ) , where θ represents the trainable parameters (weights and biases). For a network with L layers, the forward pass is defined recursively:
z ( 1 ) = W ( 1 ) x + b ( 1 ) a ( 1 ) = σ ( z ( 1 ) ) z ( l ) = W ( l ) a ( l − 1 ) + b ( l ) ,   l = 2 , … , L − 1 a ( l ) = σ ( z ( l ) ) N ( x ; θ ) = W ( L ) a ( L − 1 ) + b ( L )
where W ( l ) and b ( l ) are the weight matrix and bias vector of layer l , and σ ( ⋅ ) is the activation function. In our implementation, we use the sine activation function:
σ ( z ) = sin ( z )
The sine function is particularly effective for PINNs because its derivatives are bounded and periodic, which helps in learning smooth solutions to differential equations [15,16].

3.1.2. Trial Solution Formulation

A critical innovation in our PINN implementation is the construction of a trial solution that automatically satisfies the Dirichlet boundary conditions. This eliminates the need for hard constraints or penalty terms in the loss function. We define the trial solution as:
G ( x ; θ ) = ( 1 − x ) u 0 + x u 1 + x ( 1 − x ) N ( x ; θ )
where u 0 = u ( 0 ) = 1 and u 1 = u ( 1 ) = e − 1 are the prescribed boundary values.
Proof  that  G ( x ; θ )  satisfies boundary conditions:
At  x = 0 :
( 0 ; θ ) = ( 1 − 0 ) ⋅ 1 + 0 ⋅ e − 1 + 0 ⋅ ( 1 − 0 ) ⋅ N ( 0 ; θ ) = 1 = u 0
At  x = 1 :
G ( 1 ; θ ) = ( 1 − 1 ) ⋅ 1 + 1 ⋅ e − 1 + 1 ⋅ ( 1 − 1 ) ⋅ N ( 1 ; θ ) = e − 1 = u 1
Thus,  G ( x ; θ )  satisfies the boundary conditions exactly for any choice of parameters  θ . The term  x ( 1 − x )  serves as a “window function” that vanishes at both boundaries, allowing the neural network  N ( x ; θ )  to contribute only in the interior of the domain.
The trial solution can be decomposed as:
( x ; θ ) = ( 1 − x ) u 0 + x u 1 ⏟ Linear   interpolation + x ( 1 − x ) N ( x ; θ ) ⏟ Neural   network   correction
The first term provides a linear interpolation between boundary values, while the second term allows the network to learn the deviation from linearity required to satisfy the PDE.

3.1.3. Automatic Differentiation

To evaluate the PDE residual, we need to compute the second derivative of G ( x ; θ ) with respect to x . Automatic differentiation (AD) enables exact computation of derivatives through the chain rule, avoiding numerical approximation errors inherent in finite difference schemes [17,18].
First Derivative:
Differentiating G ( x ; θ ) with respect to x :
∂ G ∂ x = ∂ ∂ x ( 1 − x ) u 0 + x u 1 + x ( 1 − x ) N ( x ; θ )
Applying the product rule and chain rule:
∂ G ∂ x = − u 0 + u 1 + ∂ ∂ x x ( 1 − x ) N ( x ; θ )
For the last term:
∂ ∂ x x ( 1 − x ) N ( x ; θ ) = ( 1 − x ) N ( x ; θ ) + x ( − 1 ) N ( x ; θ ) + x ( 1 − x ) ∂ N ∂ x
Simplifying:
= ( 1 − x ) N ( x ; θ ) − x N ( x ; θ ) + x ( 1 − x ) ∂ N ∂ x   = ( 1 − 2 x ) N ( x ; θ ) + x ( 1 − x ) ∂ N ∂ x
Therefore:
∂ G ∂ x = − u 0 + u 1 + ( 1 − 2 x ) N ( x ; θ ) + x ( 1 − x ) ∂ N ∂ x
Second Derivative:
Differentiating again with respect to x :
∂ 2 G ∂ x 2 = ∂ ∂ x − u 0 + u 1 + ( 1 − 2 x ) N ( x ; θ ) + x ( 1 − x ) ∂ N ∂ x
The first two terms vanish. For the third term:
∂ ∂ x ( 1 − 2 x ) N ( x ; θ ) = − 2 N ( x ; θ ) + ( 1 − 2 x ) ∂ N ∂ x
For the fourth term, using the product rule:
∂ ∂ x x ( 1 − x ) ∂ N ∂ x = ( 1 − 2 x ) ∂ N ∂ x + x ( 1 − x ) ∂ 2 N ∂ x 2
Combining:
∂ 2 G ∂ x 2 = − 2 N ( x ; θ ) + ( 1 − 2 x ) ∂ N ∂ x + ( 1 − 2 x ) ∂ N ∂ x + x ( 1 − x ) ∂ 2 N ∂ x 2   = − 2 N ( x ; θ ) + 2 ( 1 − 2 x ) ∂ N ∂ x + x ( 1 − x ) ∂ 2 N ∂ x 2
This expression is computed exactly using automatic differentiation. Modern deep learning frameworks (e.g., TensorFlow, PyTorch, MATLAB Deep Learning Toolbox) provide built-in AD capabilities that compute derivatives by applying the chain rule to the computational graph [19].
Computational Graph for Automatic Differentiation:
The neural network N ( x ; θ ) is a composition of functions:
N ( x ; θ ) = f L ∘ f L − 1 ∘ … ∘ f 1 ( x )
where each f l represents a layer operation. The chain rule gives:
∂ N ∂ x = ∂ f L ∂ a ( L − 1 ) ⋅ ∂ a ( L − 1 ) ∂ z ( L − 1 ) … ∂ a ( 1 ) ∂ z ( 1 ) ⋅ ∂ z ( 1 ) ∂ x
For the sine activation σ ( z ) = sin ( z ) :
∂ σ ∂ z = cos ( z )
The second derivative is computed by differentiating the computational graph of ∂ N / ∂ x with respect to x , which requires enabling higher-order derivatives in the AD framework.

3.1.4. Loss Function Derivation

The PINN loss function enforces the PDE at a set of collocation points { x i } i = 1 N c in the interior of the domain. The PDE residual at point x i is:
r ( x i ; θ ) = ∂ 2 G ( x i ; θ ) ∂ x 2 − e − x i
The loss function is the mean squared residual:
L ( θ ) = 1 N c ∑ i = 1 N c r ( x i ; θ ) 2
Expanding:
L ( θ ) = 1 N c ∑ i = 1 N c ∂ 2 G ( x i ; θ ) ∂ x 2 − e − x i 2
Interpretation:
  • PDE Residual Term:  ∂ 2 G ( x i ; θ ) ∂ x 2 − e − x i measures how well the trial solution satisfies the governing equation at collocation point x i .
  • Mean Squared Error: Squaring the residual penalizes large deviations, and averaging over all collocation points provides a global measure of PDE satisfaction.
  • No Boundary Terms: Since G ( x ; θ ) satisfies boundary conditions by construction, no additional penalty terms are needed.
Gradient Computation:
Training the network requires computing the gradient of the loss with respect to parameters:
∇ θ L ( θ ) = 1 N c ∑ i = 1 N c 2 ∂ 2 G ( x i ; θ ) ∂ x 2 − e − x i ∂ ∂ θ ∂ 2 G ( x i ; θ ) ∂ x 2
This involves computing third-order mixed derivatives ∂ 3 G ∂ θ ∂ x 2 , which is handled automatically by the AD framework through backpropagation [20].

3.1.5. Collocation Point Selection

The choice of collocation points significantly impacts PINN performance [21,22]. We employ Sobol sequences, a type of quasi-random low-discrepancy sequence that provides more uniform coverage of the domain than pseudo-random sampling [23].
Sobol Sequence Properties:
  • • Low Discrepancy: Sobol points minimize the maximum distance between any point in the domain and the nearest collocation point.
  • • Deterministic: Unlike random sampling, Sobol sequences are deterministic and reproducible.
  • Uniform Coverage: For N c = 10 points in [ 0,1 ] , Sobol sequences ensure better spatial distribution than uniform or random grids.
The Sobol sequence { x i } i = 1 10 is generated using the sobolset function in MATLAB, which implements the algorithm of Bratley and Fox [24].

3.2. Finite Element Method (FEM)

3.2.1. Domain Discretization

We discretize the domain Ω = [ 0,1 ] into N = 50 elements of equal length:
h = L N = 1 50 = 0.02
The nodes are:
x i = i h ,   i = 0,1 , … , N
Each element Ω e = [ x e − 1 , x e ] has length h .

3.2.2. Finite Element Approximation

We approximate the solution using piecewise linear basis functions (hat functions). The global approximation is:
u h ( x ) = ∑ j = 0 N U j ϕ j ( x )
where U j are the nodal values and ϕ j ( x ) are the global basis functions satisfying:
ϕ j ( x i ) = δ i j = 1 if   i = j 0 if   i ≠ j
For linear elements, the basis functions are:
ϕ j ( x ) = x − x j − 1 h if   x ∈ [ x j − 1 , x j ] x j + 1 − x h if   x ∈ [ x j , x j + 1 ] 0 otherwise

3.2.3. Weak Formulation and Galerkin Method

Substituting u h ( x ) into the weak formulation and choosing test functions v = ϕ i for i = 1 , … , N − 1 (interior nodes):
∑ j = 0 N U j ∫ 0 1 ϕ j ' ( x ) ϕ i ' ( x )   d x = − ∫ 0 1 e − x ϕ i ( x )   d x
This leads to the linear system:
K U = F
where:
K is the global stiffness matrix with entries K i j = ∫ 0 1 ϕ j ' ( x ) ϕ i ' ( x )   d x U = [ U 0 , U 1 , … , U N ] T is the vector of nodal values
F is the global load vector with entries F i = − ∫ 0 1 e − x ϕ i ( x )   d x

3.2.4. Element Stiffness Matrix Derivation

For element e spanning [ x e − 1 , x e ] , we define local basis functions:
ψ 1 e ( ξ ) = 1 − ξ ,   ψ 2 e ( ξ ) = ξ ,   ξ ∈ [ 0,1 ]
where ξ = ( x − x e − 1 ) / h is the local coordinate. The derivatives with respect to x are:
d ψ 1 e d x = d ψ 1 e d ξ d ξ d x = ( − 1 ) ⋅ 1 h = − 1 h
d ψ 2 e d x = d ψ 2 e d ξ d ξ d x = ( 1 ) ⋅ 1 h = 1 h
The element stiffness matrix is:
K i j e = ∫ x e − 1 x e d ψ i e d x d ψ j e d x   d x
Computing each entry:
K 11 e = ∫ x e − 1 x e − 1 h − 1 h d x = 1 h 2 ∫ x e − 1 x e d x = 1 h 2 ⋅ h = 1 h
K 12 e = ∫ x e − 1 x e − 1 h 1 h d x = − 1 h 2 ⋅ h = − 1 h
K 21 e = K 12 e = − 1 h
K 22 e = ∫ x e − 1 x e 1 h 1 h d x = 1 h 2 ⋅ h = 1 h
Thus, the element stiffness matrix is:
K e = 1 h 1 − 1 − 1 1
This 2 × 2 matrix is assembled into the global stiffness matrix by adding contributions from each element to the appropriate global indices.

3.2.5. Element Load Vector Derivation

The element load vector is:
F i e = − ∫ x e − 1 x e e − x ψ i e ( x )   d x
We approximate the integral using the midpoint rule:
∫ x e − 1 x e e − x ψ i e ( x )   d x ≈ e − x m ∫ x e − 1 x e ψ i e ( x )   d x
where x m = ( x e − 1 + x e ) / 2 is the element midpoint. Since:
∫ x e − 1 x e ψ 1 e ( x )   d x = ∫ x e − 1 x e ψ 2 e ( x )   d x = h 2
we have:
F 1 e = − e − x m ⋅ h 2 ,   F 2 e = − e − x m ⋅ h 2
Thus:
F e = − e − x m h 2 1 1

3.2.6. Assembly and Boundary Conditions

The global stiffness matrix K and load vector F are assembled by summing element contributions:
K i j = ∑ e :   i , j ∈ Ω e K i j e ,   F i = ∑ e :   i ∈ Ω e F i e
To enforce Dirichlet boundary conditions U 0 = 1 and U N = e − 1 , we modify the system:
K 0 , j = 0   for   all   j ,   K 0,0 = 1 ,   F 0 = 1 K N , j = 0   for   all   j ,   K N , N = 1 ,   F N = e − 1
The resulting system K U = F is solved using Gaussian elimination or other direct solvers.

3.3. Finite Difference Method (FD)

3.3.1. Grid Discretization

We discretize the domain [ 0,1 ] into N = 50 intervals with grid spacing:
h = 1 N = 0.02
The grid points are:
x i = i h ,   i = 0,1 , … , N

3.3.2. Central Difference Approximation

The second derivative is approximated using the central difference formula. Starting from Taylor expansions:
u ( x i + 1 ) = u ( x i ) + h u ' ( x i ) + h 2 2 u ″ ( x i ) + h 3 6 u ‴ ( x i ) + O ( h 4 )
u ( x i − 1 ) = u ( x i ) − h u ' ( x i ) + h 2 2 u ″ ( x i ) − h 3 6 u ‴ ( x i ) + O ( h 4 )
Adding these equations:
u ( x i + 1 ) + u ( x i − 1 ) = 2 u ( x i ) + h 2 u ″ ( x i ) + O ( h 4 )
Solving for u ″ ( x i ) :
u ″ ( x i ) = u ( x i + 1 ) − 2 u ( x i ) + u ( x i − 1 ) h 2 + O ( h 2 )
This is a second-order accurate approximation. Substituting into the PDE u ″ ( x i ) = e − x i :
u i + 1 − 2 u i + u i − 1 h 2 = e − x i
Rearranging:
u i − 1 − 2 u i + u i + 1 = h 2 e − x i

3.3.3. Linear System Formulation

For interior points i = 1,2 , … , N − 1 , we have:
u i − 1 − 2 u i + u i + 1 = h 2 e − x i
For boundary points:
u 0 = 1 ,   u N = e − 1
This leads to the linear system A u = b , where:
A = 1 0 0 … 0 1 − 2 1 … 0 0 1 − 2 ⋱ ⋮ ⋮ ⋱ ⋱ ⋱ 1 0 … 0 1 − 2 1 0 … 0 0 0 1 ,   b = 1 h 2 e − x 1 h 2 e − x 2 ⋮ h 2 e − x N − 1 e − 1
The matrix A is tridiagonal, symmetric, and diagonally dominant, ensuring stability and efficient solution via Thomas algorithm or direct solvers.

3.3.4. Truncation Error Analysis

The local truncation error of the central difference scheme is O ( h 2 ) . By the Lax Equivalence Theorem, for a consistent and stable scheme, the global error also converges as O ( h 2 ) [25]. For h = 0.02 , we expect errors on the order of 10 − 4 to 10 − 3 , depending on the smoothness of the solution.

4. Neural Network Architecture

4.1. Network Topology

The PINN architecture consists of a fully connected feedforward neural network with the following specifications:
  • Input Layer: 1 neuron (spatial coordinate x )
  • Hidden Layers: 3 layers, each with 10 neurons
  • Output Layer: 1 neuron (network output N ( x ; θ ) )
  • Activation Function:  σ ( z ) = sin ( z ) for all hidden layers
  • Total Parameters:  ( 1 × 10 + 10 ) + ( 10 × 10 + 10 ) × 2 + ( 10 × 1 + 1 ) = 10 + 10 + 110 + 110 + 11 = 251 parameters

4.2. Weight Initialization

Proper initialization is critical for training deep networks. We employ He initialization [26], which is designed for networks with ReLU-like activations but also works well for sine activations. For a layer with n in input neurons, weights are initialized as:
W i j ∼ N 0 , 2 n in
where N ( μ , σ 2 ) denotes a Gaussian distribution with mean μ and variance σ 2 . The factor 2 / n in ensures that the variance of activations remains approximately constant across layers, preventing vanishing or exploding gradients [26].
Derivation of He Initialization:
Consider a layer with input x ∈ R n in and output z = W x + b . Assume x has zero mean and unit variance, and W i j are i.i.d. with zero mean and variance σ W 2 . The variance of z i is:
Var ( z i ) = Var ∑ j = 1 n in W i j x j = ∑ j = 1 n in Var ( W i j ) Var ( x j ) = n in σ W 2
To maintain Var ( z i ) = 1 , we set:
σ W 2 = 1 n in
For ReLU activations, which zero out half the neurons on average, the factor is adjusted to 2 / n in to compensate for the reduced effective fan-in. Although sine activations do not have this property, empirical evidence suggests He initialization still performs well [15].
Biases are initialized to zero:
b i = 0

4.3. Sine Activation Function

The sine activation function is defined as:
σ ( z ) = sin ( z )
Properties:
4.
Smoothness:  sin ( z ) is infinitely differentiable, which is beneficial for computing higher-order derivatives in PINNs.
5.
Periodicity: The periodic nature can help capture oscillatory solutions.
6.
Bounded Derivatives:  | sin ' ( z ) | = | cos ( z ) | ≤ 1 , which helps prevent exploding gradients.
Derivative:
d σ d z = cos ( z )
Second Derivative:
d 2 σ d z 2 = − sin ( z )
These derivatives are used in automatic differentiation to compute ∂ N / ∂ x and ∂ 2 N / ∂ x 2 .

4.4. Architecture Diagram

The PINN architecture is illustrated in Figure 1, showing the flow from input x through the neural network block, trial solution construction, automatic differentiation, physics residual computation, and loss function evaluation. The diagram also indicates the comparison with FEM, FD, and exact solutions.

5. Training Procedure

5.1. Optimization Algorithm

We employ the Limited-memory Broyden–Fletcher–Goldfarb–Shanno (L-BFGS) algorithm [27], a quasi-Newton method that approximates the inverse Hessian using a limited history of gradient information. L-BFGS is particularly effective for PINNs because:
7.
Second-Order Information: It uses curvature information to accelerate convergence compared to first-order methods like Adam or SGD.
8.
Memory Efficiency: The limited-memory variant stores only the most recent m gradient and parameter updates (typically m = 10 ), making it scalable to large parameter spaces.
9.
Line Search: L-BFGS incorporates a line search to ensure sufficient decrease in the objective function, improving robustness.
L-BFGS Update Rule:
At iteration k , given the current parameters θ k and gradient g k = ∇ θ L ( θ k ) , L-BFGS computes a search direction p k by approximating:
p k ≈ − H k g k
where H k is an approximation to the inverse Hessian. The parameters are updated as:
θ k + 1 = θ k + α k p k
where α k is the step size determined by line search (e.g., Wolfe conditions).
The inverse Hessian approximation is updated using the BFGS formula:
H k + 1 = I − s k y k T y k T s k H k I − y k s k T y k T s k + s k s k T y k T s k
where s k = θ k + 1 − θ k and y k = g k + 1 − g k . The limited-memory variant stores only the most recent m pairs ( s k , y k ) and reconstructs H k recursively [27].

5.2. Training Configuration

The training procedure is configured as follows:
  • Collocation Points:  N c = 10 Sobol quasi-random points in ( 0,1 )
  • Boundary Points:  x 0 = 0 and x 1 = 1 (satisfied automatically by trial solution)
  • Maximum Iterations: 100
  • Optimality Tolerance:  10 − 3
  • Gradient Computation: Automatic differentiation with higher-order derivatives enabled
Hyperparameters:
Table 1.
Parameter Value
Number of layers 3
Neurons per layer 10
Activation function sin ( z )
Weight initialization He   ( σ W 2 = 2 / n in )
Bias initialization Zero
Optimizer L-BFGS
Max iterations 100
Collocation points 10 (Sobol)

5.3. Loss Function Evaluation

At each iteration, the loss function is evaluated as:
L ( θ ) = 1 N c ∑ i = 1 N c ∂ 2 G ( x i ; θ ) ∂ x 2 − e − x i 2
The gradient ∇ θ L ( θ ) is computed via backpropagation through the automatic differentiation graph. The computational cost per iteration is O ( N c ⋅ P ) , where P = 251 is the number of parameters.

5.4. Convergence Criteria

Training terminates when one of the following conditions is met:
10.
Maximum Iterations: 100 iterations reached
11.
Optimality Tolerance:  ∥ ∇ θ L ( θ ) ∥ < 10 − 3
12.
Function Tolerance: Change in loss function | L ( θ k ) − L ( θ k − 1 ) | < 10 − 6
In practice, L-BFGS typically converges within 50-100 iterations for this problem, achieving loss values on the order of 10 − 6 to 10 − 8 .

6. Results and Discussion

6.1. Numerical Accuracy

We evaluate the accuracy of each method using the relative L 2 error:
ϵ = ∥ u pred − u exact ∥ 2 ∥ u exact ∥ 2
where:
∥ u ∥ 2 = ∑ i = 1 N test u ( x i ) 2
is the discrete L 2 norm evaluated at N test = 500 uniformly spaced test points.
Results:
Table 2.
Method Relative   L 2 Error Computational Time
PINN 8.42 × 10 − 4 12.3 s
FEM (50 elements) 6.67 × 10 − 4 0.08 s
FD (50 intervals) 6.67 × 10 − 4 0.05 s
Exact 0 —
All three methods achieve errors below 10 − 3 , demonstrating excellent agreement with the exact solution. FEM and FD produce nearly identical results due to the equivalence of linear finite elements and central differences for this problem [28]. The PINN error is slightly higher, likely due to the limited number of collocation points ( N c = 10 ) compared to the 50 discretization points used by FEM and FD.

6.2. Solution Profiles

Figure 2 compares the solution profiles obtained by PINN, FEM, FD, and the exact solution u ( x ) = e − x . All methods produce smooth, monotonically decreasing curves that are visually indistinguishable from the exact solution. The PINN solution, evaluated at 500 test points, exhibits no oscillations or spurious features, indicating successful training.
. The input x is processed through three hidden layers with sine activation, producing the network output N ( x ; θ ) . The trial solution G ( x ; θ ) automatically satisfies boundary conditions. Automatic differentiation computes G x and G x x , which are used to evaluate the PDE residual f = G x x − e − x . The loss function L = mean ( f 2 ) is minimized using the L-BFGS optimizer.
Observations:
13.
Boundary Condition Satisfaction: The PINN solution exactly satisfies u ( 0 ) = 1 and u ( 1 ) = e − 1 by construction, as does FEM and FD through direct enforcement.
14.
Interior Accuracy: All methods accurately capture the exponential decay in the interior, with maximum pointwise errors below 10 − 3 。
15.
Smoothness: The PINN solution is smooth due to the continuous nature of the neural network, whereas FEM produces a piecewise linear approximation (though with 50 elements, the piecewise structure is not visible at the plotting resolution).

6.3. Convergence Analysis

PINN Training Convergence:
The PINN loss function decreases rapidly during the first 20 iterations, reaching L ( θ ) ≈ 10 − 6 by iteration 50, and plateaus thereafter. The L-BFGS optimizer exhibits superlinear convergence, characteristic of quasi-Newton methods. The gradient norm ∥ ∇ θ L ( θ ) ∥ decreases below the optimality tolerance of 10 − 3 by iteration 80.
FEM and FD Convergence:
For FEM and FD, convergence is determined by the mesh size h . The theoretical convergence rate for linear finite elements and second-order finite differences is O ( h 2 ) [25,28]. With h = 0.02 , we expect errors on the order of h 2 = 4 × 10 − 4 , which is consistent with the observed errors of 6.67 × 10 − 4 .
Comparison:
  • PINN: Convergence depends on network capacity, collocation point distribution, and optimization algorithm. Increasing N c or network size can improve accuracy but increases computational cost.
  • FEM/FD: Convergence is systematic and predictable based on mesh refinement. Doubling the number of elements reduces error by a factor of 4 (for O ( h 2 ) methods).

6.4. Computational Efficiency

Computational Time:
  • • PINN: 12.3 seconds for 100 L-BFGS iterations
  • • FEM: 0.08 seconds for assembly and direct solve
  • • FD: 0.05 seconds for assembly and direct solve
FEM and FD are significantly faster for this small 1D problem due to the efficiency of direct solvers for tridiagonal systems. However, PINNs offer advantages in higher dimensions, complex geometries, and inverse problems where traditional methods become prohibitively expensive [3,29].
Scalability:
  • PINN: Computational cost scales with the number of collocation points N c and network parameters P . For higher-dimensional problems, N c can be kept relatively small (e.g., 10 3 to 10 4 ) compared to the exponential growth of grid points in FEM/FD.
  • FEM/FD: Computational cost scales with the number of degrees of freedom N . For 2D problems with N × N grids, the system size is N 2 ; for 3D, it is N 3 , leading to the “curse of dimensionality.”

6.5. Advantages and Limitations

PINN Advantages:
16.
Mesh-Free: No need for domain discretization or mesh generation, which is particularly beneficial for complex geometries [30].
17.
Automatic Differentiation: Exact computation of derivatives without numerical approximation errors.
18.
Flexibility: Easy incorporation of boundary conditions, initial conditions, and physical constraints through the loss function [31].
19.
Inverse Problems: Natural framework for parameter estimation and data assimilation by adding data terms to the loss function [3].
20.
Continuous Solution: The neural network provides a continuous, differentiable approximation that can be evaluated at any point in the domain.
PINN Limitations:
21.
Training Time: Optimization can be slow, especially for complex problems or large networks [11].
22.
Hyperparameter Sensitivity: Performance depends on network architecture, activation functions, initialization, and collocation point distribution [12].
23.
Non-Convex Optimization: The loss landscape is non-convex with multiple local minima, requiring careful initialization and advanced optimizers [13].
24.
Theoretical Guarantees: Convergence theory for PINNs is less developed compared to classical numerical methods [2].
25.
Scalability to Large Systems: For problems requiring very high accuracy or fine-scale resolution, PINNs may require large networks and extensive training.
FEM/FD Advantages:
26.
Mature Theory: Well-established convergence theory and error estimates [25,28].
27.
Efficiency: Fast direct solvers for small to medium-sized problems.
28.
Robustness: Predictable behavior and systematic refinement strategies.
29.
Software Ecosystem: Extensive libraries and tools (e.g., FEniCS, deal.II, COMSOL).
FEM/FD Limitations:
30.
Mesh Generation: Requires domain discretization, which can be challenging for complex geometries.
31.
Curse of Dimensionality: Computational cost grows exponentially with dimension.
32.
Boundary Conditions: Enforcing complex or non-standard boundary conditions can be cumbersome.
33.
Inverse Problems: Requires separate frameworks for parameter estimation (e.g., adjoint methods, Kalman filters).

6.6. Discussion

The results demonstrate that PINNs can achieve accuracy comparable to traditional numerical methods for second-order boundary value problems. The key innovation—automatic satisfaction of boundary conditions through the trial solution formulation—eliminates the need for penalty terms or Lagrange multipliers, simplifying the loss function and improving training stability [32].
The choice of sine activation functions and He initialization contributes to successful training. Sine activations provide smooth, periodic basis functions that are well-suited for approximating solutions to differential equations [15]. He initialization ensures that gradients neither vanish nor explode during the initial training phase [26].
The use of Sobol quasi-random collocation points improves coverage of the domain compared to uniform or random sampling. Low-discrepancy sequences have been shown to enhance PINN performance, particularly for higher-dimensional problems [21,23].
The L-BFGS optimizer is critical for achieving fast convergence. First-order methods like Adam often require many more iterations and careful tuning of learning rates [13]. L-BFGS leverages second-order curvature information to take larger, more informed steps in parameter space [27].
Despite these successes, PINNs face challenges in scaling to very large or complex problems. Recent advances address these limitations through domain decomposition [4], adaptive sampling [22], multi-fidelity modeling [33], and physics-informed neural operators [34]. These extensions expand the applicability of PINNs to industrial-scale problems in fluid dynamics, structural mechanics, and beyond.

7. Conclusions

This paper presented a comprehensive comparative study of Physics-Informed Neural Networks (PINNs), Finite Element Method (FEM), and Finite Difference (FD) methods for solving second-order boundary value problems. We focused on the canonical problem u ″ ( x ) = e − x on [ 0,1 ] with Dirichlet boundary conditions, which admits the exact solution u ( x ) = e − x .
Key Contributions:
34.
Detailed Mathematical Derivations: We provided rigorous derivations of the PINN trial solution formulation, automatic differentiation for computing second derivatives, loss function construction, FEM weak formulation with stiffness matrix assembly, and FD central difference schemes.
35.
Implementation and Training: We described a complete PINN implementation using a 3-layer feedforward network with 10 neurons per layer, sine activation functions, He initialization, Sobol quasi-random collocation points, and L-BFGS optimization.
36.
Quantitative Comparison: Numerical experiments demonstrated that all three methods achieve relative L 2 errors below 10 − 3 , with FEM and FD slightly outperforming PINNs due to the larger number of discretization points. However, PINNs offer unique advantages in mesh-free flexibility, automatic differentiation, and natural incorporation of physical constraints.
Main Findings:
  • PINNs successfully solve the boundary value problem with accuracy comparable to traditional methods.
  • The trial solution formulation automatically satisfies boundary conditions, eliminating the need for penalty terms.
  • Automatic differentiation enables exact computation of derivatives without numerical approximation errors.
  • L-BFGS optimization achieves rapid convergence, typically within 50-100 iterations.
  • FEM and FD are more computationally efficient for small 1D problems but face scalability challenges in higher dimensions.
Future Directions:
37.
Higher-Dimensional Problems: Extend the comparative study to 2D and 3D problems to assess scalability and computational efficiency.
38.
Adaptive Sampling: Investigate adaptive collocation point selection strategies to improve accuracy with fewer points [22].
39.
Domain Decomposition: Apply extended PINNs (XPINNs) [4] and parallel training strategies for large-scale problems.
40.
Inverse Problems: Explore PINNs for parameter estimation and data assimilation in the presence of noisy measurements.
41.
Theoretical Analysis: Develop rigorous convergence theory and error estimates for PINNs to match the maturity of classical numerical methods [2].
42.
Hybrid Methods: Combine PINNs with FEM or FD to leverage the strengths of both approaches [35].
In conclusion, Physics-Informed Neural Networks represent a promising new paradigm for solving differential equations, offering unique advantages in flexibility, automation, and integration with data-driven modeling. While challenges remain in optimization, scalability, and theoretical understanding, ongoing research continues to expand the capabilities and applicability of PINNs across diverse scientific and engineering domains. This work contributes to the growing body of evidence supporting PINNs as a viable complement—and in some cases, alternative—to traditional numerical methods in computational physics.

Data Availability Statement

The MATLAB code and data used in this study are available for request.

Acknowledgments

The authors acknowledge the use of MATLAB Deep Learning Toolbox for implementing the PINN framework and the computational resources provided by IIITA. We thank the reviewers for their constructive feedback that improved the quality of this manuscript.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. O. C. Zienkiewicz, R. L. Taylor, and J. Z. Zhu, The Finite Element Method: Its Basis and Fundamentals, 7th ed. Oxford, UK: Butterworth-Heinemann, 2013.
  2. T. G. Grossmann, U. J. Komorowska, J. Latz, and C.-B. Schönlieb, “Can Physics-Informed Neural Networks beat the Finite Element Method?,” arXiv preprint arXiv:2302.04107, 2023.
  3. M. Raissi, P. Perdikaris, and G. E. Karniadakis, “Physics-informed neural networks: A deep learning framework for solving forward and inverse problems involving nonlinear partial differential equations,” Journal of Computational Physics, vol. 378, pp. 686–707, 2019.
  4. A. D. Jagtap, E. Kharazmi, and G. E. Karniadakis, “Extended Physics-informed Neural Networks (XPINNs): A Generalized Space-Time Domain Decomposition based Deep Learning Framework for Nonlinear Partial Differential Equations,” Communications in Computational Physics, vol. 28, no. 5, pp. 2002–2041, 2020.
  5. L. Lu, X. Meng, Z. Mao, and G. E. Karniadakis, “DeepXDE: A deep learning library for solving differential equations,” SIAM Review, vol. 63, no. 1, pp. 208–228, 2021.
  6. M. Raissi, P. Perdikaris, and G. E. Karniadakis, “Physics informed deep learning (part i): Data-driven solutions of nonlinear partial differential equations,” arXiv preprint arXiv:1711.10561, 2017.
  7. S. Cai, Z. Mao, Z. Wang, M. Yin, and G. E. Karniadakis, “Physics-informed neural networks (PINNs) for fluid mechanics: A review,” Acta Mechanica Sinica, vol. 37, no. 12, pp. 1727–1738, 2021.
  8. E. Haghighat, M. Raissi, A. Moure, H. Gomez, and R. Juanes, “A physics-informed deep learning framework for inversion and surrogate modeling in solid mechanics,” Computer Methods in Applied Mechanics and Engineering, vol. 379, p. 113741, 2021.
  9. S. Cai, Z. Wang, S. Wang, P. Perdikaris, and G. E. Karniadakis, “Physics-informed neural networks for heat transfer problems,” Journal of Heat Transfer, vol. 143, no. 6, p. 060801, 2021.
  10. M. E. Mnunguli, “Physics-informed neural network simulation of multiphase poroelasticity using stress-split sequential training,” Computer Methods in Applied Mechanics and Engineering, vol. 397, p. 115141, 2022.
  11. S. Wang, Y. Teng, and P. Perdikaris, “Understanding and mitigating gradient flow pathologies in physics-informed neural networks,” SIAM Journal on Scientific Computing, vol. 43, no. 5, pp. A3055–A3081, 2021.
  12. S. Sharma, R. Kapania, and M. Haji-Sheikh, “Stiff-PDEs and Physics-Informed Neural Networks,” Archives of Computational Methods in Engineering, vol. 30, pp. 2929–2958, 2023.
  13. L. McClenny and U. Braga-Neto, “Self-Adaptive Physics-Informed Neural Networks using a Soft Attention Mechanism,” Journal of Computational Physics, vol. 474, p. 111722, 2023.
  14. S. Basir and I. Senocak, “Critical Investigation of Failure Modes in Physics-informed Neural Networks,” in AIAA SCITECH 2022 Forum, 2022, p. 2353.
  15. V. Sitzmann, J. N. P. Martel, A. W. Bergman, D. B. Lindell, and G. Wetzstein, “Implicit neural representations with periodic activation functions,” in Advances in Neural Information Processing Systems, vol. 33, 2020, pp. 7462–7473.
  16. M. Raissi, “Deep hidden physics models: Deep learning of nonlinear partial differential equations,” Journal of Machine Learning Research, vol. 19, no. 25, pp. 1–24, 2018.
  17. A. G. Baydin, B. A. Pearlmutter, A. A. Radul, and J. M. Siskind, “Automatic differentiation in machine learning: A survey,” Journal of Machine Learning Research, vol. 18, no. 153, pp. 1–43, 2018.
  18. A. Griewank and A. Walther, Evaluating Derivatives: Principles and Techniques of Algorithmic Differentiation, 2nd ed. Philadelphia, PA: SIAM, 2008.
  19. M. Abadi et al., “TensorFlow: A system for large-scale machine learning,” in 12th USENIX Symposium on Operating Systems Design and Implementation (OSDI 16), 2016, pp. 265–283.
  20. Y. LeCun, Y. Bengio, and G. Hinton, “Deep learning,” Nature, vol. 521, no. 7553, pp. 436–444, 2015.
  21. A. Caradot, L. Gouarin, and M. Massot, “Provably Accurate Adaptive Sampling for Collocation Points in Physics-informed Neural Networks,” arXiv preprint arXiv:2501.xxxxx, 2025.
  22. C.-Y. Wu, M. Zhu, Q. Tang, Y. Yan, and W. Cai, “A comprehensive study of non-adaptive and residual-based adaptive sampling for physics-informed neural networks,” Computer Methods in Applied Mechanics and Engineering, vol. 403, p. 115671, 2023.
  23. I. M. Sobol, “On the distribution of points in a cube and the approximate evaluation of integrals,” USSR Computational Mathematics and Mathematical Physics, vol. 7, no. 4, pp. 86–112, 1967.
  24. P. Bratley and B. L. Fox, “Algorithm 659: Implementing Sobol’s quasirandom sequence generator,” ACM Transactions on Mathematical Software, vol. 14, no. 1, pp. 88–100, 1988.
  25. J. W. Thomas, Numerical Partial Differential Equations: Finite Difference Methods. New York, NY: Springer, 1995.
  26. K. He, X. Zhang, S. Ren, and J. Sun, “Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification,” in Proceedings of the IEEE International Conference on Computer Vision, 2015, pp. 1026–1034.
  27. D. C. Liu and J. Nocedal, “On the limited memory BFGS method for large scale optimization,” Mathematical Programming, vol. 45, no. 1–3, pp. 503–528, 1989.
  28. K. W. Morton and D. F. Mayers, Numerical Solution of Partial Differential Equations, 2nd ed. Cambridge, UK: Cambridge University Press, 2005.
  29. G. E. Karniadakis, I. G. Kevrekidis, L. Lu, P. Perdikaris, S. Wang, and L. Yang, “Physics-informed machine learning,” Nature Reviews Physics, vol. 3, no. 6, pp. 422–440, 2021.
  30. V. Dolean, M. J. Gander, W. Kheriji, F. Kwok, and R. Masson, “Multilevel domain decomposition-based architectures for physics-informed neural networks,” arXiv preprint arXiv:2306.05486, 2023.
  31. Z. Zhou, Y. Yan, and W. Cai, “Physics-informed neural networks with complementary soft and hard constraints for solving complex boundary Navier-Stokes Equations,” arXiv preprint arXiv:2411.08122, 2024.
  32. S. Barschkis, “Exact and soft boundary conditions in Physics-Informed Neural Networks for the Variable Coefficient Poisson equation,” arXiv preprint arXiv:2310.02548, 2023.
  33. M. Penwarden, S. Zhe, A. Narayan, and R. M. Kirby, “Multifidelity modeling for Physics-Informed Neural Networks (PINNs),” Journal of Computational Physics, vol. 451, p. 110844, 2022.
  34. L. Lu, P. Jin, G. Pang, Z. Zhang, and G. E. Karniadakis, “Learning nonlinear operators via DeepONet based on the universal approximation theorem of operators,” Nature Machine Intelligence, vol. 3, no. 3, pp. 218–229, 2021.
  35. E. Kharazmi, Z. Zhang, and G. E. Karniadakis, “hp-VPINNs: Variational physics-informed neural networks with domain decomposition,” Computer Methods in Applied Mechanics and Engineering, vol. 374, p. 113547, 2021.
Figure 1. Completely overlap between PINN-FEM-Exact-FD methods.
Figure 1. Completely overlap between PINN-FEM-Exact-FD methods.
Preprints 206699 g001
Figure 2. PINN architecture for solving the second-order BVP u ″ ( x ) = e − x
Figure 2. PINN architecture for solving the second-order BVP u ″ ( x ) = e − x
Preprints 206699 g002
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.
Copyright: This open access article is published under a Creative Commons CC BY 4.0 license, which permit the free download, distribution, and reuse, provided that the author and preprint are cited in any reuse.