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.
댓글 수: 0
채택된 답변
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)
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:
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
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
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
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 Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!