Help to approximate this integral...

11 views (last 30 days)
Peter Clifford
Peter Clifford on 3 Mar 2019
Edited: David Goodmanson on 15 Mar 2019
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 Comments
Peter Clifford
Peter Clifford on 6 Mar 2019
No f is asolution of an ODE equation, I have an approximation of it by ode45 method.
darova
darova on 6 Mar 2019
Edited: darova on 6 Mar 2019
but what f depends on? If we calculate integral x = [0, 3], what will be f (for example y = 1.56)
have you relation ?

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 6 Mar 2019
Edited: David Goodmanson on 6 Mar 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 Comments
Peter Clifford
Peter Clifford on 6 Mar 2019
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 on 7 Mar 2019
Edited: David Goodmanson on 15 Mar 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.

Sign in to comment.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!