Modal (free-vibration) analysis of a beam
Performs a modal analysis on a simply-supported beam and compares the first two natural frequencies (weak-axis and strong-axis bending) with the analytical Euler–Bernoulli formula:
f₁ = (π/L)² / (2·π) × √(E·I / (ρ·A))
The model before it is solved: its parts, supports (red) and loads (blue).
Open in 3D turn it, cut it, hide parts: in xfea's viewer, in your browser
The script
Section titled “The script”examples/scripts/02_core_concepts/steps/modal_analysis.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/steps/modal_analysis.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/steps/modal_analysis.py.
from math import pi
from xfea.problem import ModalAnalysisfrom xfea.problem import Problem
from xfea_examples import out_dirfrom xfea_examples.models import cantilever_beam_modelfrom xfea_examples.models import _nodes_at_extreme
# Model — simply-supported beam (pin at both ends)beam_length = 3000 # [mm] beam spanbeam_width = 50 # [mm] cross-section widthbeam_height = 100 # [mm] cross-section heightmesh_target = 100 # [mm] target element size
model, part, _, material, section, length = cantilever_beam_model( name="modal_beam", length=beam_length, width=beam_width, height=beam_height, target=mesh_target, fix_start=False,)
# Simply-supported: pin at start and endstart_nodes = _nodes_at_extreme(part.nodes, axis="x", mode="min")end_nodes = _nodes_at_extreme(part.nodes, axis="x", mode="max")model.add_pin_bc(nodes=start_nodes)model.add_pin_bc(nodes=end_nodes)
# Problemproblem = model.add_problem(Problem(name="modal_beam"))modal = ModalAnalysis(modes=4)problem.add_step(modal)
problem.analyse_and_extract(path=out_dir(model.name), verbose=True)
# Results and validationfrequencies = list(modal.frequencies)
# Analytical frequencies for a simply-supported beam (SI-mm consistent):# fₙ = (n·π/L)² / (2·π) × √(E·I / (ρ·A))L = length # [mm]E = material.E # [MPa]rho = material.density # [t/mm^3]A = section.A # [mm^2]Iyy = section.Iyy # [mm^4] weak-axis (z-bending, orientation [0,1,0])Ixx = section.Ixx # [mm^4] strong-axis (y-bending)
f1_weak = (pi / L) ** 2 / (2 * pi) * (E * Iyy / (rho * A)) ** 0.5f1_strong = (pi / L) ** 2 / (2 * pi) * (E * Ixx / (rho * A)) ** 0.5
print("Modal analysis: simply-supported beam")print(f" length={beam_length}, b={beam_width}, h={beam_height}")print()print(f"Analytical f1 weak axis (z-bending): {f1_weak:.4f} Hz")print(f"Analytical f1 strong axis (y-bending): {f1_strong:.4f} Hz")print()for i, f in enumerate(frequencies, 1): print(f"FEA mode {i}: {f:.4f} Hz")© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them