how to evaluate integral for given input function ?

1 次查看(过去 30 天)
Hi guys, Please check the picture below.
A = [a1 a2 a3 ....] A is given, they are temperature number array. You can assume any value you want.
u = [1 2 3 4 ...] u is the time, like hours
So, this temperature functino x(u), will be feed into function out (t, x(t)) to do the intergation. This output of "out" will be only between [0 1] for any given time, t. t is just like u, >=0.

采纳的回答

John D'Errico
John D'Errico 2021-8-24
编辑:John D'Errico 2021-8-24
No, you don't want to fit a polynomial to that vector. Polynomials are just bad news for anything.
After seeing the your picture of the real data, here is what I would do. I would use a spline model to interpolate the data, actually pchip may be the best choice. The nice thing about a spline is you can integrate it easily.
First though, since I don't really have any actual data, let me build some. You seem to have a highly oscillatory pattern that repeats multiple times. I'll just use a simple sinusoial curve as an example.
H = 0:100;
T = 330 + 20*sin(H) + 10*sin(3*H);
plot(H,T,'o-')
That should be close enough. Now, while I could interpolate that curve, and then use that function to integrate the exponential function...
For example, a simple solution might be:
C = 0.01;
B = 4.5e3;
X_t = pchip(H,T);
fun = @(t) C*exp(-B./fnval(X_t,t));
Now, for any time t, we can produce an integral value from 0 to that point in time. The problem is, this function does not have an analytical integral form. At best, we might use integral to perform the numerical integration. For example:
out = @(t) integral(fun,0,t);
out(10)
ans = 1.5630e-07
And that is ok, except that integral is not well vectorized for this sort of problem.
Perhaps better is to build the spline differently. Then we will simply integrate the resulting spline model directly.
K_t = pchip(H,C*exp(-B./T));
So you can see I have chosen to build a spline model of the exponential form that you have inside the integral. We can integrate that spline directly. fnint comes from the curve fitting toolbox, as I recall.
K_int = fnint(K_t);
fnval(K_int,23) % the integral from 0 to 23 is:
ans = 3.4148e-07
fnplt(K_int) % and it is easy to plot the resulting function, as a function
fnval is also nicely vectorized, so you can generate the integral you want at any list of points.
If you lack the curve fitting toolbox, I would get it. It is very useful. But if not, things like fnint are not that difficult to write.
  3 个评论
sun
sun 2021-8-24
编辑:sun 2021-8-24
@John D'Errico. thank you so much for your kindness and help! Allow me to read carefully, I will give you a reply no later than tomorrow.
John D'Errico
John D'Errico 2021-8-24
It should do what you want, I think. If you don't have the curvefitting toolbox tell me, but it is well worth the money as a nice set of tools.

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2021-8-24
You don't have a function, you have a vector of data. Unless you know the form of the function x(u) from the theory underlying your original problem consider trapz or cumtrapz to integrate the data directly.
  3 个评论
Steven Lord
Steven Lord 2021-8-24
Based on the other question to which you linked, what you want to integrate is essentially a stairs plot?
x = 0:0.5:5;
y = x(randperm(numel(x)));
stairs(x, y)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by