how to evaluate integral for given input function ?

조회 수: 5 (최근 30일)
sun
sun 2021년 8월 24일
편집: sun 2021년 8월 26일
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)
sun
sun 2021년 8월 25일
thank you!

댓글을 달려면 로그인하십시오.

카테고리

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