Double integrate a precise series of numbers

Hi All, I'm very new in Matlab and I would like to ask about this situation. I'm getting some data from my accelerometer, and I directly putting them in a file using this format:
X: 125, x: 103, Y: 127, y: 106, Z: 051, z: 043
X: 120, x: 100, Y: 129, y: 108, Z: 054, z: 045
X: 123, x: 103, Y: 127, y: 106, Z: 053, z: 044
....
X: 111, x: 093, Y: 135, y: 113, Z: 053, z: 044
I want to double integrate for example just the X axis, I know that I can use "integral2" to do that, but it needs a defined function as parameter. in my case is a set of numbers.
Note that the time is t = 1.5s, and the number of lines (readings from the accelerometer) is 78.
how can double integrate it using only this set of numbers?
Thanks in advance.

댓글 수: 18

Please explain: X, x, Y, y, Z, z. It’s not obvious what your data are and which ones you want to integrate.
You have vectors of accelerations, so the trapz function is your friend here.
Med
Med 2014년 6월 2일
Ok, I changed it so I can have result just from the X axis, then my files contains this:
X: 125
X: 120
X: 123
...
x:125
I want to double integrate the result to get the displacement, thanks.
José-Luis
José-Luis 2014년 6월 2일
You haven't really answered Star's question...
Med
Med 2014년 6월 3일
@José_Luis, those numbers are readings from the accelerometer, X means that the reading is from X axis,
I hope it's clear now.
José-Luis
José-Luis 2014년 6월 3일
Maybe I am being dense, but it still is not clear to me. X is what? Position? Time? Moles? Apples? Oranges?
x? Position? Time? Number of remaining orang-utans?
Nowhere in your data do you show time.
Med
Med 2014년 6월 3일
X is the acceleration in the x axis. :)
Note that the time is t = 1.5s
José-Luis
José-Luis 2014년 6월 3일
And what is x?
Med
Med 2014년 6월 3일
Dear @josé_Luis, don't worry about the "x"
let's say I have a set of numbers like 125 126 126 127 128 129 131 .... 126 126 125.
I only need how to double integrate this values, thanks.
José-Luis
José-Luis 2014년 6월 3일
편집: José-Luis 2014년 6월 3일
The double of integral of a function of a single variable makes no sense.
You can integrate f(x). A double integral of f(x) does not exist.
The double integral of f(x,y) can be found.
You only give us f(x) (if even that).
Once you have defined what you actually want, please look at
integral2() for numerical integration.
int() for symbolic integration.
Med
Med 2014년 6월 3일
well yes and no, I mentioned f(x) and I mentioned the time.
to be clear about it : here is a plot, the x axis is the time, the y axis is the acceleration values:
this is basically a plot from the set of numbers I have in my file.
José-Luis
José-Luis 2014년 6월 3일
You cannot get a double integral from what you show.
Med
Med 2014년 6월 3일
can you elaborate @josé,
José-Luis
José-Luis 2014년 6월 3일
편집: José-Luis 2014년 6월 3일
A double integral for a function of one variable does not exist. It is not defined. You cannot compute it. You need a function of two variables for that.
Med
Med 2014년 6월 3일
the first variable is acceleration the second is time!
José-Luis
José-Luis 2014년 6월 3일
편집: José-Luis 2014년 6월 4일
What you show is the acceleration as a function of time. That is a function of one variable. Therefore the double integral cannot be calculated. For that you need acceleration as a function of time and something else.
Med
Med 2014년 6월 4일
@josé what do you think about @A Jenkins's answer; it quit what I'm looking for.
José-Luis
José-Luis 2014년 6월 4일
I don't know because I don't understand what you want. But if you want to obtain position and distance from the acceleration, it looks like A. Jenkins does what you want.
In that case you are not performing a double integral, you are integrating two times. That is not the same thing.
The only caveat would then be that you would need to assume a position and a speed at time t=0, if you don't know them.
Please accept A. Jenkins' answer if it helped you.
Med
Med 2014년 6월 4일
thank you @José for your clarification,

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

 채택된 답변

A Jenkins
A Jenkins 2014년 6월 3일

1 개 추천

I am going to guess that these are accelerations sampled at given times. The poster wants the integral over time to find the velocity, and the second integral over time to find the position. We need to approximate the integral with a cumulative sum.
% given
del_t=1.5; % seconds
accel_x=[125 126 126 127 128 129 131 126 126 125];
% need to know initial position and velocity
v_0=0;
x_0=0;
% time vector corresponding to data
t=del_t*(0:(length(accel_x)-1));
% compute integrals
vel_x=del_t*cumtrapz(accel_x)+v_0; %or cumsum()
pos_x=del_t*cumtrapz(vel_x)+x_0; %or cumsum()
% examine results
plot(t,accel_x, t,vel_x, t,pos_x);
legend('accel_x','vel_x','pos_x');

댓글 수: 3

Med
Med 2014년 6월 4일
편집: Med 2014년 6월 4일
Thank you @A Jenkins, I just want to ask you about the following line:
t=del_t*(0:(length(accel_x)-1));
what does this line do?
A Jenkins
A Jenkins 2014년 6월 4일
You didn't include time stamps with your data, so this makes a vector of time stamps to go with each data point.
The syntax (0:some_number) makes a vector like [0, 1, 2, 3, 4 ... some_number],
In this case, the vector of time stamps is the same length as the acceleration vector,
and then it is multiplied by del_t to get [0, 1.5, 3.0, ... 13.5].
Med
Med 2014년 6월 4일
I got it, thanks.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

Med
2014년 6월 2일

편집:

2014년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by