BEAM_DEFLECTION
Calculates the vertical deflection of a structural beam at a given point x along its span. The function assembles the beam, applies the supplied supports and loads, solves the beam, and then evaluates the deflection curve at the requested coordinate.
In Euler-Bernoulli beam theory, deflection is the displacement field produced by bending. The governing relationship is
E I \frac{d^4 v}{dx^4} = w(x)
where E is Young’s modulus, I is the second moment of area, v(x) is the beam deflection, and w(x) is the applied load distribution. Positive results indicate upward deflection, and negative results indicate downward deflection.
Excel Usage
=BEAM_DEFLECTION(span, supports, loads, query_x, e_modulus, second_moment)
span(float, required): Total length of the beam (m).supports(list[list], required): 2D array of support definitions [[x, rx, ry, rm]].loads(list[list], required): 2D array of load definitions [[type, val1, val2, x1, x2]].query_x(float, required): The x-coordinate at which to evaluate deflection (m).e_modulus(float, optional, default: 200000000000): Young’s Modulus (Pa).second_moment(float, optional, default: 0.00000905): Second moment of area (m4).
Returns (float): Vertical deflection (m) at the specified coordinate.
Example 1: Midspan deflection of simply supported beam
Inputs:
| span | supports | loads | query_x | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 10 | 0 | 0 | 1 | 0 | point | -1000 | 0 | 5 | 0 | 5 |
| 10 | 0 | 1 | 0 |
Excel formula:
=BEAM_DEFLECTION(10, {0,0,1,0;10,0,1,0}, {"point",-1000,0,5,0}, 5)
Expected output:
-0.0115101
Example 2: Tip deflection of cantilever
Inputs:
| span | supports | loads | query_x | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5 | 0 | 1 | 1 | 1 | udl | -100 | 0 | 0 | 5 | 5 |
Excel formula:
=BEAM_DEFLECTION(5, {0,1,1,1}, {"udl",-100,0,0,5}, 5)
Expected output:
-0.0043163
Example 3: Deflection at point between supports
Inputs:
| span | supports | loads | query_x | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 8 | 0 | 0 | 1 | 0 | point | -500 | 0 | 4 | 0 | 2 |
| 8 | 0 | 1 | 0 |
Excel formula:
=BEAM_DEFLECTION(8, {0,0,1,0;8,0,1,0}, {"point",-500,0,4,0}, 2)
Expected output:
-0.00202578
Example 4: Zero deflection at support
Inputs:
| span | supports | loads | query_x | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 6 | 0 | 0 | 1 | 0 | point | -100 | 0 | 3 | 0 | 0 |
| 6 | 0 | 1 | 0 |
Excel formula:
=BEAM_DEFLECTION(6, {0,0,1,0;6,0,1,0}, {"point",-100,0,3,0}, 0)
Expected output:
0
Python Code
Show Code
from indeterminatebeam import Beam, Support
from indeterminatebeam.loading import PointLoadV, PointLoadH, PointTorque, UDLV, TrapezoidalLoadV
def beam_deflection(span, supports, loads, query_x, e_modulus=200000000000, second_moment=9.05e-06):
"""
Calculate the deflection of a beam at a specific coordinate.
See: https://indeterminatebeam.readthedocs.io/en/main/docstrings.html#indeterminatebeam.Beam.get_deflection
This example function is provided as-is without any representation of accuracy.
Args:
span (float): Total length of the beam (m).
supports (list[list]): 2D array of support definitions [[x, rx, ry, rm]].
loads (list[list]): 2D array of load definitions [[type, val1, val2, x1, x2]].
query_x (float): The x-coordinate at which to evaluate deflection (m).
e_modulus (float, optional): Young's Modulus (Pa). Default is 200000000000.
second_moment (float, optional): Second moment of area (m4). Default is 9.05e-06.
Returns:
float: Vertical deflection (m) at the specified coordinate.
"""
try:
def to2d(value):
return [[value]] if not isinstance(value, list) else value
supports = to2d(supports)
loads = to2d(loads)
if not isinstance(supports, list) or not all(isinstance(row, list) for row in supports):
return "Error: Invalid input - supports must be a 2D list"
if not isinstance(loads, list) or not all(isinstance(row, list) for row in loads):
return "Error: Invalid input - loads must be a 2D list"
beam = Beam(span=span, E=e_modulus, I=second_moment)
support_rows = []
has_x_restraint = False
for row in supports:
if len(row) < 4:
continue
try:
x_pos = float(row[0])
rx_raw = float(row[1])
ry_raw = float(row[2])
rm_raw = float(row[3])
except (TypeError, ValueError):
continue
kx = rx_raw if rx_raw > 1 else None
ky = ry_raw if ry_raw > 1 else None
rx_fixed = int(bool(rx_raw)) if kx is None else 0
ry_fixed = int(bool(ry_raw)) if ky is None else 0
rm_fixed = int(bool(rm_raw))
if rx_fixed == 1 or (kx is not None and kx > 0):
has_x_restraint = True
support_rows.append({
"x": x_pos,
"fixed": (rx_fixed, ry_fixed, rm_fixed),
"kx": kx,
"ky": ky,
})
if not support_rows:
return "Error: At least one valid support is required"
if not has_x_restraint:
support_rows[0]["fixed"] = (1, support_rows[0]["fixed"][1], support_rows[0]["fixed"][2])
support_rows[0]["kx"] = None
for support in support_rows:
beam.add_supports(Support(support["x"], fixed=support["fixed"], kx=support["kx"], ky=support["ky"]))
for row in loads:
if len(row) < 2:
continue
l_type = str(row[0]).lower()
try:
val1 = float(row[1])
val2 = float(row[2]) if len(row) > 2 else 0.0
x1 = float(row[3]) if len(row) > 3 else 0.0
x2 = float(row[4]) if len(row) > 4 else 0.0
except (TypeError, ValueError):
continue
if l_type == "point":
beam.add_loads(PointLoadV(val1, x1))
elif l_type == "moment":
beam.add_loads(PointTorque(val1, x1))
elif l_type == "udl":
beam.add_loads(UDLV(val1, (x1, x2)))
elif l_type == "trap":
beam.add_loads(TrapezoidalLoadV((val1, val2), (x1, x2)))
elif l_type == "point_h":
beam.add_loads(PointLoadH(val1, x1))
beam.analyse()
return float(beam.get_deflection(query_x))
except Exception as e:
return f"Error: {str(e)}"