Lesson 1 of 18

Arc Length

Arc Length

The length of a curve y=f(x)y = f(x) from aa to bb:

L=intabsqrt1+[f(x)]2,dxL = int_a^b sqrt{1 + [f'(x)]^2} , dx

Why It Works

At each xx, the curve moves right by dxdx and up by f(x)dxf'(x)dx. By the Pythagorean theorem, the infinitesimal piece has length sqrtdx2+(fdx)2=sqrt1+f2,dxsqrt{dx^2 + (f'dx)^2} = sqrt{1+f'^2} , dx.

Examples

Straight line y=mxy = mx on [a,b][a, b]: f=mf' = m, so L=(ba)sqrt1+m2L = (b-a)sqrt{1+m^2}

  • y=xy = x on [0,3][0,3]: L=3sqrt2approx4.2426L = 3sqrt{2} approx 4.2426
  • y=3xy = 3x on [0,4][0,4]: L=4sqrt10approx12.6491L = 4sqrt{10} approx 12.6491

Numerical Approach

Use the midpoint rule with a central difference derivative:

double dx = (b - a) / n;
for each midpoint x:
    double deriv = (f(x+h) - f(x-h)) / (2*h);
    sum += my_sqrt(1.0 + deriv * deriv);
return sum * dx;

Your Task

Implement double arc_length(double (*f)(double), double a, double b, int n, double h).

Use the midpoint rule with step dx=(ba)/ndx = (b-a)/n and central difference with step hh for the derivative. A Newton's-method sqrt helper is provided.

TCC compiler loading...
Loading...
Click "Run" to execute your code.