Understanding the truss element stiffness matrix calculator — concept and principle
This calculator builds the 4×4 global stiffness matrix of a two-dimensional truss (bar) element from its Young's modulus, cross-section area and the coordinates of its two nodes. It is the basic building block of the direct stiffness method used in structural analysis courses and finite-element programs.
How it is calculated
L = √((x₂ − x₁)² + (y₂ − y₁)²)
k = E × A ÷ L
c = (x₂ − x₁) ÷ L, s = (y₂ − y₁) ÷ L
K = k × [c², cs, −c², −cs; cs, s², −cs, −s²; −c², −cs, c², cs; −cs, −s², cs, s²]
- E in GPa, A in mm², coordinates in metres; k and the matrix rows are shown in kN/mm (equal to MN/m).
- The rows and columns follow the degrees of freedom u₁x, u₁y, u₂x, u₂y.
The principle
A pin-jointed bar carries only axial force, so along its own axis it behaves like a spring with stiffness EA/L: stretch it by δ and it pulls back with EA·δ/L. The global matrix expresses that same spring in x–y coordinates. A node displacement in x or y stretches the bar only by its component along the bar, which is why the direction cosines c and s appear, and the resulting axial force is again split into x and y components. Multiplying these two projections gives the c², cs and s² terms. The matrix is symmetric, and each row sums to zero because moving the whole bar without stretching it creates no force.
Worked example
Default inputs: E = 200 GPa, A = 1,000 mm², node 1 at (0, 0), node 2 at (3, 4) m.
- L = √(3² + 4²) = 5 m; angle = atan2(4, 3) = 53.13°.
- c = 3 ÷ 5 = 0.6, s = 4 ÷ 5 = 0.8.
- k = 200×10⁹ Pa × 1×10⁻³ m² ÷ 5 m = 4×10⁷ N/m = 40 kN/mm.
- c²k = 0.36 × 40 = 14.4; csk = 0.48 × 40 = 19.2; s²k = 0.64 × 40 = 25.6.
- Row 1 = 14.4 19.2 −14.4 −19.2; Row 2 = 19.2 25.6 −19.2 −25.6; Row 3 = −14.4 −19.2 14.4 19.2; Row 4 = −19.2 −25.6 19.2 25.6.
| Young's modulus E (GPa) | Axial stiffness EA/L (kN/mm) |
|---|---|
| 50 | 10 |
| 100 | 20 |
| 150 | 30 |
| 200 | 40 |
| 250 | 50 |
| 300 | 60 |
| 400 | 80 |
How to read the result
Each entry Kij is the force at degree of freedom i caused by a unit displacement at degree of freedom j with all others held fixed. A horizontal bar has only c² terms; a vertical bar only s² terms. To analyse a whole truss, add each element's entries into a global matrix at the matching node degrees of freedom, apply supports, then solve K·u = F for the displacements.
Common mistakes
- Mixing units, for example E in MPa with A in m².
- Swapping node order inconsistently between elements; the matrix is the same either way, but displacement numbering must match the assembly.
Frequently asked questions
Why is the stiffness matrix singular?
Without supports the bar can move or rotate as a rigid body with no force, so the system has no unique solution.
Does the node order change the matrix?
Reversing the nodes flips the signs of c and s, which leaves every product in the matrix unchanged.
How do I get the member force after solving?
Axial force = k × [c, s] · (u₂ − u₁), the stretch along the bar times EA/L.
Sources: Standard direct-stiffness method for a 2-D truss element, as presented in finite-element and structural-analysis textbooks