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

# Program for critical depth in trapezoidal channel

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

- Asked in: 2068 Magh, 6 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/hydraulics/algorithm-critical-depth-trapezoidal
- Whole chapter: https://www.bctengineer.com/md/semester_4/hydraulics/chapter-7

## Question

Write algorithm and programme coding in any high level language (C or Fortran) for determination of critical depth in trapezoidal channel section.

## Short answer

The algorithm solves f(y) = Q^2 T − g A^3 = 0 for trapezoidal section with A = (b+zy)y, T = b+2zy by bisection. Bracketing the root by doubling y_high until f changes sign, then iterating to tolerance 1e-6. Example: for Q=6, b=2.5, z=2, yc = 0.691 m. The C program implements this.

## Answer

**Principle.** Critical flow requires $\dfrac{Q^2 T}{g A^3} = 1$. For a trapezoidal section with bed width $b$ and side slope $z$ (z H : 1 V):

$$
A = (b + zy)y,\quad T = b + 2zy
$$

Define $f(y) = Q^2 T - gA^3$. The critical depth is the root of $f(y) = 0$. $f > 0$ for $y < y_c$ and $f < 0$ for $y > y_c$, so the bisection method always converges.

**Algorithm**

1. Start.
2. Read $Q$, $b$, $z$. Set $g = 9.81$ and tolerance $\varepsilon = 10^{-6}$.
3. Set $y_{low} = 10^{-6}$ and $y_{high} = 1$.
4. While $f(y_{high}) > 0$, set $y_{high} = 2\,y_{high}$ (bracket the root).
5. Repeat: $y_{mid} = (y_{low} + y_{high})/2$.
   - If $f(y_{mid}) > 0$, set $y_{low} = y_{mid}$; otherwise set $y_{high} = y_{mid}$.
6. Stop repeating when $y_{high} - y_{low} < \varepsilon$.
7. Print $y_c = (y_{low} + y_{high})/2$.
8. Stop.

**Program in C**

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

/* f(y) = Q^2*T - g*A^3 ; zero at critical depth */
double f(double y, double Q, double b, double z)
{
    double A = (b + z * y) * y;
    double T = b + 2.0 * z * y;
    return Q * Q * T - G * A * A * A;
}

int main(void)
{
    double Q, b, z, lo, hi, mid, tol = 1e-6;
    int i;

    printf("Enter discharge Q (m3/s): ");
    scanf("%lf", &Q);
    printf("Enter bed width b (m): ");
    scanf("%lf", &b);
    printf("Enter side slope z (z H : 1 V): ");
    scanf("%lf", &z);

    lo = 1e-6;
    hi = 1.0;
    while (f(hi, Q, b, z) > 0.0)      /* expand until sign changes */
        hi *= 2.0;

    for (i = 0; i < 100 && (hi - lo) > tol; i++) {
        mid = 0.5 * (lo + hi);
        if (f(mid, Q, b, z) > 0.0)
            lo = mid;                 /* root is deeper */
        else
            hi = mid;                 /* root is shallower */
    }
    mid = 0.5 * (lo + hi);
    printf("Critical depth yc = %.4f m\n", mid);
    return 0;
}
```

**Sample run:** $Q = 6$, $b = 2.5$, $z = 2$ gives **$y_c = 0.6912\ \text{m}$**.

Setting $z = 0$ gives a rectangular channel and $b = 0$ gives a triangular channel, so the same program handles all three shapes.

## Check yourself

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

1. What function is driven to zero to find the critical depth?
   A. f(y) = Q^2 T - g A^3
   B. f(y) = Q - A V
   C. f(y) = A - T y
   D. f(y) = y - V^2/2g
   Answer: A. Critical flow needs Q^2 T/(g A^3) = 1, i.e. Q^2 T - g A^3 = 0. (Key point: Root function)

2. In the bisection step, if f(ymid) > 0 what is done?
   A. Set yhigh = ymid
   B. Stop the loop
   C. Set ylow = ymid, since the root is deeper
   D. Double ymid
   Answer: C. f > 0 means y < yc, so the root lies above ymid and ylow is moved up. (Key point: Bisection logic)

3. Why is yhigh doubled while f(yhigh) > 0?
   A. To increase accuracy
   B. To make sure yhigh is deeper than yc so the root is bracketed
   C. To avoid dividing by zero in A
   D. To convert units
   Answer: B. The root must lie between ylow and yhigh; doubling continues until f changes sign. (Key point: Bracketing)

4. How can the same program handle rectangular and triangular channels?
   A. By changing g
   B. By changing the tolerance
   C. It cannot
   D. Set z = 0 for rectangular and b = 0 for triangular
   Answer: D. A = (b + zy)y and T = b + 2zy reduce to the rectangular and triangular forms for those values. (Key point: Generality of program)

## Related in Hydraulics

- [Program for normal depth in trapezoidal channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-normal-depth-trapezoidal) — Hydraulics, chapter 6
- [Program for uniform depth in rectangular channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-uniform-depth-rectangular) — Hydraulics, chapter 6
- [Program for alternate depths in rectangular channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-alternate-depths-rectangular) — Hydraulics, chapter 7
- [Critical depth in four channel sections](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Acritical-depth-four-channel-sections-6-cumecs) — Hydraulics, chapter 7
- [Hump and constriction: critical depth, 2 m channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Ahump-sidewall-constriction-critical-depth-2m-wide) — Hydraulics, chapter 7, asked 2×
- [Hump and constriction: critical depth, 1.8 m channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Ahump-sidewall-constriction-critical-depth-1-8m-wide) — Hydraulics, chapter 7

## Related in other subjects

- [Efficient trapezoidal section and triangular channel depth](https://www.bctengineer.com/question.md?key=semester_6%2Fhydro_power%3Atriangular-channel-normal-depth-trap) — Hydro Power, chapter 1, asked 2×
- [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
- [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×
