Help to approximate this integral...
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am wondering if it is possible to have an approximation of this integral
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206667/image.png)
I have only an approximation
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/206668/image.png)
of f which is a solution of an ODE.
Many thanks,
Maher.
3 comentarios
Respuestas (1)
David Goodmanson
el 6 de Mzo. de 2019
Editada: David Goodmanson
el 6 de Mzo. de 2019
Hi M^2,
I am assuming that y(t) is strictly monotonic increasing or decreasing so that the inverse exists. It's good if the y and t arrays are not too sparse. Depending on how time comsuming the ode solver is, in the case of ode45, for example, you can output a lot of points by specifying a grid of points in the tspan input variable rather than just an upper and lower limit.
Assuming that t and y are reasonably dense an that the y array starts at 0, then
V(x) = cumtrapz(exp(-t),y)
There are better ways to do an indefinite integral, but this gives a reasonable result if exp(-t) is fairly smooth,
2 comentarios
David Goodmanson
el 7 de Mzo. de 2019
Editada: David Goodmanson
el 15 de Mzo. de 2019
HI Maher,
I should have been more explicit. Yes, I took y = f(t). Then
t = f^-1(y)
This is consistent with just using the line
[t, y] = ode45(@odefunc, tspan, [0; 1], options);
There are two side-by-side output arrays, t and y = f(t). These match up point-by-point. But if both of these arrays are monotonic there is no reason you can't consider y to be the independent variable, t the dependent variable and redefine the arrays as y and t(y), the inverse function of y. Since t and y match up point-by point, t is the same as t(y) and
Int {0,x} e-t(y) dy ---> Int {0,x} e-t dy.
With y as the independent variable you can do the definite integral from 0 to x by trapz (assuming the y array starts at 0) and the indefinite integral by cumtrapz to give the function V(x).
Matlab has plenty of integral evaluation capability when given a function f(x) that can be evaluated at arbitrary points in x.
I hope I'm wrong, but if what you have is an independent and a dependent array at fixed points, I don't know that Matlab has anything easily available that's better than the lamentably primitive trapz and cumtrapz.
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!