---
title: "Program for alternate depths in rectangular channel"
subject: "Hydraulics"
chapter: 7
key: "semester_4/hydraulics:algorithm-alternate-depths-rectangular"
source: https://www.bctengineer.com/q/semester_4/hydraulics/algorithm-alternate-depths-rectangular
site: BCT Engineering
---

# Program for alternate depths in rectangular channel

Hydraulics · Chapter 7: Energy and Momentum Principles in Open channel flow

- Asked in: 2069 Poush, 6 marks
- Video: [Specific energy and alternate depth in a rectangular channel | Open Channel Flow](https://www.youtube.com/watch?v=Ok3dSdIMh_w) — The Study Sphere
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/hydraulics/algorithm-alternate-depths-rectangular
- Whole chapter: https://www.bctengineer.com/md/semester_4/hydraulics/chapter-7

## Question

Write algorithm and program coding in any high level language (C or Fortran) for computing alternate depths in a rectangular channel section.

## Short answer

Use the specific energy equation E = y + q²/(2gy²). Given one depth, compute E; solve for the other root by Newton-Raphson, starting on the opposite side of critical depth yc. Example: for Q=5 m³/s, b=3 m, y₁=1.5 m, the alternate depth y₂ = 0.3403 m.

## Answer

**Principle.** For a given discharge, two depths (one subcritical, one supercritical) have the same specific energy. For a rectangular channel with $q = Q/b$:

$$
E = y + \frac{q^2}{2gy^2},\qquad y_c = \left(\frac{q^2}{g}\right)^{1/3},\qquad E_{min} = 1.5\,y_c
$$

Given depth $y_1$, find $E$, then find the other root $y_2$ of $f(y) = y + \dfrac{q^2}{2gy^2} - E = 0$ by Newton-Raphson, with $f'(y) = 1 - \dfrac{q^2}{gy^3}$. The starting guess is taken on the opposite side of $y_c$ from $y_1$ so that the other root is found.

**Algorithm**

1. Start.
2. Read $Q$, $b$, $y_1$. Set $g = 9.81$.
3. Compute $q = Q/b$, $y_c = (q^2/g)^{1/3}$ and $E = y_1 + q^2/(2g\,y_1^2)$.
4. If $E < 1.5\,y_c$, print "flow not possible" and stop.
5. If $y_1 > y_c$, set $y_2 = 0.5\,y_c$; otherwise set $y_2 = 2\,y_c$.
6. Repeat: $y_{new} = y_2 - f(y_2)/f'(y_2)$ (if $y_{new} \le 0$, halve $y_2$ instead).
7. Stop when $|y_{new} - y_2| < 10^{-8}$; set $y_2 = y_{new}$.
8. Print $E$, $y_c$ and $y_2$.
9. Stop.

**Program in C**

```c
#include <stdio.h>
#include <math.h>
#define G 9.81

int main(void)
{
    double Q, b, y1, q, E, yc, y2, f, df, yn;
    int i;

    printf("Enter Q (m3/s), b (m), y1 (m): ");
    scanf("%lf %lf %lf", &Q, &b, &y1);

    q  = Q / b;
    yc = cbrt(q * q / G);                      /* critical depth */
    E  = y1 + q * q / (2.0 * G * y1 * y1);     /* specific energy */

    if (E < 1.5 * yc - 1e-9) {
        printf("E is less than Emin = %.4f m : flow impossible\n", 1.5 * yc);
        return 0;
    }
    /* start on the opposite side of yc */
    y2 = (y1 > yc) ? 0.5 * yc : 2.0 * yc;

    for (i = 0; i < 100; i++) {
        f  = y2 + q * q / (2.0 * G * y2 * y2) - E;
        df = 1.0 - q * q / (G * y2 * y2 * y2);
        if (fabs(df) < 1e-12) break;
        yn = y2 - f / df;
        if (yn <= 0.0) yn = 0.5 * y2;          /* keep depth positive */
        if (fabs(yn - y2) < 1e-8) { y2 = yn; break; }
        y2 = yn;
    }
    printf("E = %.4f m, yc = %.4f m\n", E, yc);
    printf("Alternate depth y2 = %.4f m\n", y2);
    return 0;
}
```

**Sample run:** $Q = 5\ \text{m}^3/\text{s}$, $b = 3\ \text{m}$, $y_1 = 1.5\ \text{m}$ gives $E = 1.5629\ \text{m}$, $y_c = 0.6567\ \text{m}$ and **alternate depth $y_2 = 0.3403\ \text{m}$**.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Alternate depths are two depths that have:
   A. The same specific force
   B. The same discharge and the same specific energy (one sub-, one supercritical)
   C. The same velocity
   D. The same Froude number
   Answer: B. For a given Q and E, E = y + q^2/(2gy^2) has one subcritical and one supercritical root. (Key point: Alternate depths)

2. Why does the algorithm test E < 1.5 yc?
   A. To select the starting guess
   B. To detect supercritical flow
   C. To check tolerance
   D. Because below Emin no real depth exists, so flow is not possible
   Answer: D. Minimum specific energy for the discharge is 1.5 yc; a lower E cannot carry q. (Key point: Feasibility check)

3. Why is the Newton starting guess placed on the opposite side of yc from y1?
   A. So that Newton converges to the other root, not to y1 again
   B. To make f'(y) zero
   C. To keep E constant
   D. To speed up printing
   Answer: A. Starting near y1 would return y1; starting across yc finds the alternate depth. (Key point: Starting guess)

4. What is f'(y) in the Newton-Raphson iteration?
   A. 1 + q^2/(g y^3)
   B. 1 - q^2/(g y^3)
   C. q^2/(g y^2)
   D. 1 - q^2/(2 g y^2)
   Answer: B. Differentiating y + q^2/(2gy^2) gives 1 - q^2/(g y^3). (Key point: Newton derivative)

## Related in Hydraulics

- [Program for uniform depth in rectangular channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-uniform-depth-rectangular) — Hydraulics, chapter 6
- [Froude number ratio for alternate depths](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalternate-depths-froude-number-ratio) — Hydraulics, chapter 7
- [Specific energy from alternate depths](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aspecific-energy-in-terms-of-alternate-depths) — Hydraulics, chapter 7
- [Program for critical depth in trapezoidal channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-critical-depth-trapezoidal) — Hydraulics, chapter 7
- [Program for normal depth in trapezoidal channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-normal-depth-trapezoidal) — Hydraulics, chapter 6
- [Hydraulic exponent for rectangular section 10/3](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Ahydraulic-exponent-rectangular-10-3) — Hydraulics, chapter 6, asked 2×

## Related in other subjects

- [High level languages; C versus FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ahll-types-c-vs-fortran) — Computer Programming, chapter 1
- [High level languages and natural language](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ahll-similar-natural-language) — Computer Programming, chapter 1
- [Most economical rectangular channel section](https://www.bctengineer.com/question.md?key=semester_6%2Fhydro_power%3Amost-economical-rectangular-section) — Hydro Power, chapter 1, asked 2×
- [Efficient rectangular section and triangular channel depth](https://www.bctengineer.com/question.md?key=semester_6%2Fhydro_power%3Atriangular-channel-normal-depth-rect) — Hydro Power, chapter 1, asked 2×
