Buoyancy and Stability of Floating Bodies
Summary
This interactive MATLAB Live Script teaches the buoyancy and stability of floating bodies with rectangular, circular and triangular cross-sections. Students set the dimensions, the densities, the heel angle and the water level. The script then locates the centroid (G), the center of buoyancy (B) and the metacenter (M), finds the equilibrium draft, and classifies the body as stable, unstable or neutral from the metacentric height and the restoring or overturning moment. It includes guided steps, activities, challenge problems and an evaluation rubric.
Keywords: buoyancy, floating body stability, Archimedes' principle, hydrostatics, fluid mechanics, metacenter, metacentric height, center of buoyancy, righting moment, MATLAB Live Script, engineering education.
Learning Goals
Students learn how a floating body reaches vertical equilibrium and how its stability is determined. Specifically, they should be able to:
Apply Archimedes' principle to compute the buoyant force and relate the submerged fraction of a body to the density ratio.
Explain the difference between the centroid of the body (G), which stays fixed in the body, and the center of buoyancy (B), which moves as the submerged region changes shape.
Locate the metacenter (M) and compute the metacentric radius (BM = I/V) and the metacentric height (GM) for upright and heeled bodies.
Classify the equilibrium as stable, unstable or neutral, and relate that classification to the direction of the righting moment.
Recognize how the shape of the cross-section and the width of the waterline control stability, including why a homogeneous circular section is always neutral.
How MATLAB is used and how it improves learning
MATLAB turns a topic usually taught with a few static textbook figures into an interactive experiment. Students change the shape, dimensions, densities, heel angle and water level, and immediately see B and M move and the moment switch between restoring and overturning. Cases that are tedious by hand, such as large heel angles, triangular hulls or a non-equilibrium draft, become easy to explore.
The Live Script places the theory, the equations, the code and the results side by side, so each equation connects directly to the code that implements it. The script also reuses a bracketing root-finding method to compute the equilibrium draft. This shows students that numerical methods from other courses solve real engineering problems.
Higher-order thinking skills
Critical thinking: students predict how B, M and the moment will change before running a section, then compare their prediction with the result. They also judge whether a given draft is a true equilibrium position.
Computation and model development: the body is modeled as a polygon. Students see how geometric algorithms (rotation, clipping against the waterline, the shoelace formula) produce the physical quantities, and they can extend the model with new shapes.
Verification and analysis: the Challenge problems ask students to validate numerical results against analytical expressions and to find stability limits, such as the minimum width or the range of densities that make a body stable.
Synthesis: students combine statics, geometry of areas, hydrostatics and numerical methods in a single model.
Other skills
When the activity is assessed with the evaluation rubric, students practice technical writing. They report results with correct units, support their conclusions with plots and tables, and justify the stability classification. If instructors ask groups to present their Challenge solutions, the activity also develops oral communication and teamwork. It can also prepare students for a laboratory session on floating-body stability with a physical model.
Context for Use
This activity is for undergraduate engineering students in a first course in Fluid Mechanics or Hydraulics, usually in the second or third year of mechanical, civil, naval, mechatronics or materials engineering. It was designed at a public technological university and works for class sizes from small groups of 15–20 students to sections of about 40. In large sections, students can work in pairs on their own computers or with MATLAB Online.
It can be used as a guided classroom activity, a computer lab session, or a short homework assignment. The guided steps (Steps 1–7) take one session of about 90–120 minutes. The Challenge problems and the rubric-based report can be assigned as one week of homework. Instructors can also run only the Interactive Explorer as a 15–20 minute in-class demonstration after the lecture on stability of floating bodies.
The activity fits right after the topics of hydrostatic forces and Archimedes' principle, as the application lesson on the stability of immersed and floating bodies. Students should already know the following concepts:
Statics: free-body diagrams, force and moment equilibrium, and the sign conventions for rotations.
Geometry: centroids and area moments of inertia of plane figures.
Hydrostatics: hydrostatic pressure, buoyant force and density.
Numerical methods: basic familiarity with bracketing methods such as bisection or false position helps but is not required.
The activity is easy to adapt to other settings. The input parameters are controls, so the same script works for an introductory demonstration or for a more advanced assignment. The geometry functions accept any convex polygon, so instructors can add new cross-sections, for example a trapezoidal hull. They can also extend the activity with a righting-arm curve GZ(θ) for a naval architecture course. The script runs in MATLAB R2025a or later, including MATLAB Online, and needs no additional toolboxes.
MATLAB skills students must have mastered before the activity:
Students need only introductory MATLAB experience. They should be able to:
Open and run a Live Script, section by section, with Run Section or Run and Advance.
Modify variable values, either directly or through interactive controls such as edit fields and sliders.
Read basic code: assignment statements, arithmetic expressions, if/else statements and for loops.
Interpret 2-D plots and output displayed in the Command Window or inline.
Experience with structures and local functions is helpful for the Challenge problems, which ask students to modify the code. It is not needed to complete the guided steps, because each step explains the code it runs.
Description and Teaching Materials
The activity is delivered through a single MATLAB Live Script that students open in MATLAB R2025a or later, or in MATLAB Online. It runs in three stages.
Introduction (5–10 minutes). The instructor reviews Archimedes' principle and the idea of stability using the Description section of the script. This section explains the roles of the centroid G, the center of buoyancy B and the metacenter M, and the stable, unstable and neutral cases.
Guided steps (60–90 minutes). Students run the script section by section with Run Section or Run and Advance. In Definition of input parameters they choose the cross-section (rectangular, circular or triangular) and enter its dimensions and the densities of the body and the fluid. They then work through seven steps:
Step 1 builds the section as a polygon and computes its area and centroid G with the shoelace formula.
Step 2 checks whether the body floats by comparing densities.
Step 3 applies a heel angle and a water level, rotating the body about G.
Step 4 clips the polygon at the free surface to obtain the submerged area, the center of buoyancy B, the buoyant force and the weight.
Step 5 finds the equilibrium draft with a bisection method.
Step 6 computes the metacentric radius BM and the metacentric height GM, and locates M.
Step 7 computes the righting arm and moment, draws the complete diagram (G, B, M, forces and restoring or overturning moment) and reports the verdict.
Each step combines a short explanation, the governing equation, a few lines of code and a plot or numerical output. Note and Activity boxes ask students to change parameters and predict the outcome before they run the section again.
Exploration and assessment (rest of the class or homework). In the Interactive Buoyancy and Stability Explorer, all the controls sit in one section, so every change immediately updates the diagram, the verdict and a results table. Students then solve the Challenge problems: they find the minimum width that makes a rectangular section stable and verify it analytically, explain why a circular section is always neutral, find the range of densities that make a triangular section stable, and replace the bisection method with the False Position Method. The instructor grades the work with the Evaluation Rubric at the end of the script.
How MATLAB is used
MATLAB does all the geometric and physical computation. It defines the cross-section as a polygon, rotates it, clips it against the waterline, computes areas, centroids and forces, and solves for the equilibrium draft. It also produces the plots that show the body, the water, the symmetry axis, the forces and the points G, B and M. The Live Editor's interactive controls (edit fields and sliders) let students change the inputs without editing code. The local functions at the end of the script show students how a complete engineering model is organized.
Could other software be used?
The same analysis could be programmed in Python (NumPy and Matplotlib), Julia, or a spreadsheet for the simplest upright cases. Interactive geometry tools such as GeoGebra could show the shapes, but they do not easily compute the forces and the equilibrium draft. MATLAB was chosen for four reasons:
One document: the Live Script holds the theory, the equations, the code, the interactive controls and the results, and students run it section by section.
No setup: no package installation is needed, and the script runs in MATLAB Online, which matters for students without their own computers.
Campus availability: MATLAB is available to all students through the institutional license.
Connection with other courses: the script reuses code structures and numerical methods that students already learned in MATLAB in their numerical methods course.
Materials
Buoyancy and Stability of Floating Bodies Live Script (buoyancy_stability_floating_bodies.m, plain text Live Script format). This is the main material. It contains the learning objectives, usage instructions, theory, the seven guided steps, the interactive explorer, the challenge problems, the evaluation rubric and all local functions. It is provided in editable plain text so that instructors can modify the parameters, the text and the code.
PDF export of the Live Script (optional). A read-only copy with the outputs already computed, made with Export → PDF in the Live Editor. Students can review the steps or print it without running MATLAB.
Evaluation rubric (included in the Live Script; optionally also as a separate Word file). Five criteria with four performance levels: interpretation of G, B and M; computation of forces and draft; stability classification; modification of the script; and communication of results. A Word version lets instructors adapt the weights to their course.
Background reading (optional)
Any introductory fluid mechanics textbook that covers the stability of immersed and floating bodies, for example: Çengel, Y. A., & Cimbala, J. M. Fluid Mechanics: Fundamentals and Applications. McGraw-Hill Education (chapter on fluid statics, section on stability of immersed and floating bodies).
buoyancy_stability_floating_bodies (Matlab File 253kB Oct21 26)
Teaching Notes and Tips
**Teaching Notes**
**Working with MATLAB and the Live Script**
- **Run sections in order the first time.** Each step uses variables created in the previous ones, so running Step 6 before Step 5 produces an "undefined variable" error. Ask students to press **Run** once at the start, or to use **Run and Advance** from the top.
- **A control only re-runs its own section.** After changing a value in *Definition of input parameters* or in Step 3, students must keep pressing **Run and Advance** for the following steps to use the new value. Students often think the script is "not updating" when they simply have not re-run the later sections. The *Interactive Explorer* avoids this because all its controls and calculations are in one section.
- **Use Output Inline.** In the *Output on Right* layout, figures and text drift away from the code that produces them, which makes the step-by-step reading harder.
- **Shape names are case-sensitive.** The shape must be exactly `"Rectangular"`, `"Circular"` or `"Triangular"`. Typing `"rectangular"` causes an error. A drop-down control prevents this.
- **Edit fields accept any number.** The script stops with a clear message if a dimension or density is not positive, or if the heel angle is outside −90° to 90°. Tell students these messages are intentional.
- **Keep a clean copy.** Ask students to work on a copy of the file so they can return to the original defaults after modifying the code for the Challenge problems.
- **Class demonstration.** For a quick demonstration, use **View → Hide Code** in the *Interactive Explorer* so that only the controls and the diagram are visible.
**Common areas of confusion**
- **G versus B.** Students often think G moves when the body heels. Stress that G is fixed in the body (homogeneous body), while B moves because the shape of the submerged region changes. Step 3 is a good moment to ask students to predict where B will move before running Step 4.
- **Non-equilibrium drafts.** In Steps 3 and 4 the water level is set freely, so in general FB ≠ W and the position is not physically possible for a body floating at rest. The script reports whether the body would rise or sink. From Step 5 on, the body is analyzed at its equilibrium draft. Make this distinction explicit, because students may otherwise draw stability conclusions from a non-equilibrium state.
- **Two definitions of M.** For the upright body, M comes from BM = I/V (initial metacenter, valid for small angles). For a heeled body, M is the intersection of the vertical through B with the symmetry axis. The two coincide only near θ = 0. At large angles the value of BM printed in Step 6 still uses the upright formula with the current waterline, so it should not be compared directly with GM.
- **The circle is always neutral.** Students sometimes report this as an error. It is a good discussion point: for a homogeneous cylinder every diameter is an axis of symmetry, B always lies directly below G, and M coincides with G.
- **Sign convention.** Positive angles heel the body to the right (clockwise), and the moment of FB about G is positive counterclockwise. A restoring moment therefore has the opposite rotational sense to the heel. Students who use the opposite convention in their hand calculations may report the wrong sign.
- **Water level percentage.** The level is a percentage of the vertical height of the heeled body, not of the original height h. The same percentage gives a different draft when the angle changes.
- **Fully submerged or dry bodies.** If the body is fully submerged, B coincides with G and M is not defined, so the script reports neutral equilibrium. If the body is out of the water, there is no buoyant force. Both are limiting cases, not errors.
**Things that need reinforcement**
- **Per-unit-length analysis.** The analysis is two-dimensional, per unit length of a prismatic body. The length ℓ cancels in BM = I/V, but it does affect the forces. Remind students that real ships also have longitudinal stability, which this activity does not cover.
- **Homogeneous body.** The body is assumed homogeneous, so G is the centroid of the section. Ask advanced students how ballast or cargo would move G, and how that would change GM.
- **Verify against analytical results.** Ask students to check at least one case by hand. The upright rectangle is ideal: GM = b²/(12d) + d/2 − h/2. The first Challenge problem is built around this check.
**Practical tips**
- **Predict, then run.** Before each Activity, ask students to write a prediction: Will B move left or right? Will the moment restore or overturn? Then run the section. The comparison drives most of the learning.
- **Contrasting cases.** A rectangle with b = 2 m and h = 1 m (stable) and one with b = 1 m and h = 2 m (unstable), at the same density, show clearly how geometry controls stability.
- **Group work.** In pairs, one student can operate the controls while the other records predictions and results for the report.
- **Older figures piling up.** If students see figures drawn on top of each other after editing the code, they should use **Clear All Output** and run the script again.
- **Linking to a lab.** If a physical floating model is available, compare the predicted heel behavior with the experiment. In that case, follow the usual precautions for water near computers and electrical equipment.
Assessment
**Assessment**
I assess the activity with the five-criterion *Evaluation Rubric* included at the end of the Live Script. It rates interpretation of G, B and M; computation of forces and draft; stability classification; modification of the script; and communication of results. Each criterion has four levels, from Beginning to Excellent.
Students submit their completed Live Script, or a PDF export of it, with their predictions, results and conclusions. The main evidence comes from three sources:
- **Predictions in the Activities.** Students write what they expect before running a section and then explain any differences from the result. This shows whether they understand how B and M move with the heel angle and the draft.
- **Challenge problems.** Results that students can verify are the most objective evidence: the minimum stable width of the rectangular section, checked against the analytical expression for GM; the explanation of why the circular section is always neutral; and the range of densities that keeps the triangular section stable.
- **Code modification.** Replacing the bisection method with the False Position Method and comparing iterations shows whether students can read, modify and validate the code.
The goals are considered met when students correctly classify the equilibrium of new cases and justify the classification with GM, the righting arm and the direction of the moment. They must also report forces and drafts with correct units and verify at least one numerical result analytically. A short in-class concept question can confirm individual understanding in group work, for example predicting whether a given section is stable before running the explorer.
References and Resources
An introductory fluid mechanics textbook. Its chapter on fluid statics covers buoyancy and the stability of immersed and floating bodies at the level of this activity.
White, F. M. (2016). Fluid Mechanics (8th ed.). McGraw-Hill Education.
A widely used undergraduate textbook. Its hydrostatics chapter derives the metacentric height and works examples of floating-body stability that students can use to check the script's results.
Biran, A., & López-Pulido, R. (2014). Ship Hydrostatics and Stability (2nd ed.). Butterworth-Heinemann.
A more advanced treatment of hydrostatics, the metacenter, large-angle stability and righting-arm (GZ) curves, with MATLAB examples. Recommended for instructors who want to extend the activity to naval architecture.
Tupper, E. C. (2013). Introduction to Naval Architecture (5th ed.). Butterworth-Heinemann.
Covers ship flotation and stability, including initial and large-angle stability, with a practical engineering focus. Useful background for discussing how the two-dimensional model relates to real vessels.
Sutherland, I. E., & Hodgman, G. W. (1974). Reentrant polygon clipping. Communications of the ACM, 17(1), 32–42.
The original description of the polygon clipping algorithm the script uses to obtain the submerged region below the waterline. Useful for students who want to understand or extend the geometric part of the code.