To integrate this correctly, you will need compute all values of q(z) in the range [0, h]. If q0
and qh
are N-by-1 column vectors, this means that q
should be an N-by-M matrix, where M is the number of sample points in the range [0, h].
First, lets define z
properly:
z = linspace(0, h, 200); %// M=200, but it's an arbitrary number to your choosing
The computation of q
can be reduced to:
q = q0 * exp(-kd * z);
and qh
actually equals to the final column of q
, i.e q(:, end)
.
The integral itself can be approximated to a sum and computed using sum
:
dz = z(2) - z(1);
I = sum(q, 2) * dz;
P.S.
Since q(z) = e(-kd ·z), it's simple enough for you to compute the integral analytically:
I = q0 * (1 - exp(-kd * h)) / kd;