Lesson 17 of 18
Line Integral of a Scalar Field
Line Integrals
A line integral (or path integral) integrates a scalar field along a curve :
where is the arc-length element — each tiny piece of the curve weighted by the function value at that point.
Parameterization
If the curve is given by for , then:
So:
Examples
Arc length (set ):
For a unit circle (, , ):
Integral of along -axis from 0 to 2 ():
Numerical Computation
double line_integral(double (*f)(double, double),
double (*xt)(double), double (*yt)(double),
double (*dxt)(double), double (*dyt)(double),
double a, double b, int n) {
double h = (b - a) / n, sum = 0.0;
for (int i = 0; i < n; i++) {
double t = a + i * h;
double dx = dxt(t), dy = dyt(t);
sum += f(xt(t), yt(t)) * sqrt(dx*dx + dy*dy) * h;
}
return sum;
}
Your Task
Implement double line_integral(f, xt, yt, dxt, dyt, a, b, n) using a left Riemann sum over the parameterization.
TCC compiler loading...
Loading...
Click "Run" to execute your code.