Help to approximate this integral...

11 次查看(过去 30 天)
Hello,
I am wondering if it is possible to have an approximation of this integral
I have only an approximation
of f which is a solution of an ODE.
Many thanks,
Maher.
  3 个评论
Peter Clifford
Peter Clifford 2019-3-6
No f is asolution of an ODE equation, I have an approximation of it by ode45 method.
darova
darova 2019-3-6
编辑:darova 2019-3-6
but what f depends on? If we calculate integral x = [0, 3], what will be f (for example y = 1.56)
have you relation ?

请先登录,再进行评论。

回答(1 个)

David Goodmanson
David Goodmanson 2019-3-6
编辑:David Goodmanson 2019-3-6
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 个评论
Peter Clifford
Peter Clifford 2019-3-6
Thanks for the help.
You took ?
what are the relations between and t in
V(x) = cumtrapz(exp(-t),y)
I have this
[t, f] = ode45(@odefunc, tspan, [0; 1], options);
How to deduce an approximation of V defined by :
where is the inverse function of f which is strictly increasing and
Maher.
David Goodmanson
David Goodmanson 2019-3-7
编辑:David Goodmanson 2019-3-15
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品


版本

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by