Numerical integration of function using MATLAB

332 Views Asked by At

Let $0 < v <1$ and $v_{0}$ is some fixed point in $0<v<1$. Assume that $\lambda(t)=[1.5, .5, 3.1, 7.2, .10, 1.11, 2.15, 7.6, 3.5]$ is known numerical values of $\lambda$. I want to evaluate integral $f(v)=\int_{v_{0}}^{v}\frac{1}{\lambda(t)} dt $ for different values of $v$ and also want to plot $f(v)$ vs $v$ using MATLAB. It will be really great if any one help for the same.

1

There are 1 best solutions below

0
On

You may interpolate your data to obtain a smooth function $\lambda(t)$, for example using spline, then solve the following Cauchy problem for ODE: $$ f'(v) = \frac{1}{\lambda(v)}\\ f(v_0) = 0. $$ The function ode45 may do this for you.

Edit. Since your data for $\lambda$ is scattered both splines for $\lambda$ and $\frac{1}{\lambda}$ oscillate and eventually change sign, which is meaningless. To preserve sign you may approximate $\lambda(t)$ using pchip instead.

lamval = [1.5, .5, 3.1, 7.2, .1, 1.11, 2.15, 7.6, 3.5];
v0 = 0.2;
v = linspace(v0, 1, length(lamval));

% lamspline = spline(v, lamval);
lamspline = pchip(v, lamval);
lambda = @(t) ppval(lamspline, t);

vgrid = linspace(v0, 1, 1000);

[~,f] = ode45(@(v, f) 1 ./ lambda(v), vgrid, 0);
subplot(2, 1, 1)
plot(v, lamval, 'b*', vgrid, lambda(vgrid), 'r-')
legend('data', '\lambda', 'Location', 'NW')
subplot(2, 1, 2)
plot(vgrid, f, 'b-')
legend('f', 'Location', 'NW')

enter image description here