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

# Program for uniform depth in rectangular channel

Hydraulics · Chapter 6: Uniform flow in open channel

- Asked in: 2068 Bhadra, 2+5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/hydraulics/algorithm-uniform-depth-rectangular
- Whole chapter: https://www.bctengineer.com/md/semester_4/hydraulics/chapter-6

## Question

Write algorithm and programme coding in any high level language (C or Fortran) for calculating uniform depth for rectangular channel.

## Short answer

Newton-Raphson solves f(y)=A R^(2/3)−nQ/√S₀=0, with A=by, P=b+2y, R=A/P; derivative f′(y)=R^(2/3)(5b/3−4R/3). Iterate y ← y − f/f′ from y=1 m. For b=5 m, n=0.015, Q=15 m³/s, S₀=0.0004, uniform depth y_n = 2.07 m.

## Answer

The uniform (normal) depth $y_n$ of a rectangular channel is found from Manning's equation. It is non-linear in $y$, so Newton-Raphson is used.
$$
f(y)=AR^{2/3}-\frac{nQ}{\sqrt{S_0}}=0,\qquad A=by,\quad P=b+2y,\quad R=\frac AP
$$
$$
\frac{df}{dy}=R^{2/3}\left[\frac53b-\frac43R\right],\qquad y_{new}=y-\frac{f(y)}{f'(y)}
$$

#### Algorithm
1. Start.
2. Read $b$, $n$, $Q$, $S_0$.
3. Compute the target $K_0=nQ/\sqrt{S_0}$ and take the initial guess $y=1$ m.
4. Repeat steps 5-8 up to 50 times:
5. Compute $A=by$, $P=b+2y$, $R=A/P$.
6. Compute $f=AR^{2/3}-K_0$ and $f'=R^{2/3}[(5/3)b-(4/3)R]$.
7. $y_{new}=y-f/f'$; if $y_{new}\le0$ take $y_{new}=y/2$.
8. If $|y_{new}-y|<10^{-6}$ stop; otherwise set $y=y_{new}$.
9. Print the uniform depth $y_n$.
10. Stop.

#### Program (C)
```c
#include <stdio.h>
#include <math.h>

/* Newton-Raphson for the uniform (normal) depth of a rectangular channel */
int main(void)
{
    double b, n, Q, S, y, A, P, R, f, dfdy, ynew, target;
    int i;

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

    target = n * Q / sqrt(S);        /* required value of A*R^(2/3) */
    y = 1.0;                         /* initial guess */

    for (i = 1; i <= 50; i++) {
        A = b * y;
        P = b + 2.0 * y;
        R = A / P;
        f = A * pow(R, 2.0 / 3.0) - target;
        /* d(A R^(2/3))/dy = R^(2/3) * ( (5/3) b - (2/3) R * 2 ) */
        dfdy = pow(R, 2.0 / 3.0) * ((5.0 / 3.0) * b - (4.0 / 3.0) * R);
        ynew = y - f / dfdy;
        if (ynew <= 0.0)             /* keep depth positive */
            ynew = 0.5 * y;
        if (fabs(ynew - y) < 1e-6) {
            y = ynew;
            break;
        }
        y = ynew;
    }
    printf("Uniform depth yn = %.4f m (after %d iterations)\n", y, i);
    return 0;
}
```

#### Sample run
Input: `5 0.015 15 0.0004` (b = 5 m, n = 0.015, Q = 15 m³/s, S0 = 0.0004)

Output: `Uniform depth yn = 2.0708 m (after 4 iterations)`

Check: $A=10.354$ m², $P=9.142$ m, $R=1.1325$ m, $AR^{2/3}=11.25$, $nQ/\sqrt{S_0}=11.25$ ✓.

## Check yourself

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

1. Why is an iterative method like Newton-Raphson used to find the uniform depth?
   A. Manning's equation is non-linear in y, so y cannot be isolated directly
   B. Manning's equation does not contain depth
   C. Computers cannot square roots
   D. The slope is unknown
   Answer: A. A R^(2/3) depends on y through both A and P, so y is found numerically. (Key point: Why Newton-Raphson)

2. Which function is driven to zero?
   A. f(y) = A R^(2/3) - n Q/sqrt(S0)
   B. f(y) = A R - Q
   C. f(y) = Q - n sqrt(S0)
   D. f(y) = A R^(2/3) - Q sqrt(S0)/n
   Answer: A. Manning gives A R^(2/3) = n Q/sqrt(S0), so f is the difference from this target. (Key point: Function to solve)

3. Why does the algorithm halve y when y_new is not positive?
   A. To speed up convergence
   B. To keep the depth physically positive
   C. To reduce the number of loops
   D. To avoid the stop condition
   Answer: B. A Newton step can overshoot below zero; halving y keeps a valid depth. (Key point: Positive depth safeguard)

4. What stops the iteration in the program?
   A. After exactly 4 iterations
   B. When f is negative
   C. When |y_new - y| < 1e-6, or after 50 iterations
   D. When y equals 1 m
   Answer: C. The loop breaks once successive depths differ by less than 1e-6 (limited to 50 loops). (Key point: Stopping rule)

## Related in Hydraulics

- [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 alternate depths in rectangular channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Aalgorithm-alternate-depths-rectangular) — 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
- [Normal depth in compound channel](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Acompound-channel-normal-depth-berms) — Hydraulics, chapter 6
- [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

- [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
- [Uniform flow in rectangular channel (Chezy)](https://www.bctengineer.com/question.md?key=semester_6%2Fhydro_power%3Arectangular-channel-chezy-flow) — Hydro Power, 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×
