Integral of a matrix (x = integration(v)dt) to find x in each time step - how to get it?

3 views (last 30 days)
Dear altruists,
I have these (5x1 size) time steps -
t1 = 5.000;
t2 = 5.005;
t3 = 5.015;
t4 = 5.020;
t5 = 5.025;
For each of these time steps, I have this (8x5 size) velocity matrix -
0.223886255942431 0.766594808762019 0.777477860918720 1.46402363417739 NaN
NaN 0.666581311838176 0.440897758695197 0.786687514042304 NaN
NaN 0.760744913959832 0.726179926996350 1.04378898162688 0.222809516150796
NaN 0.275556537143772 0.805109395242995 0.500274785771561 1.14165961699158
NaN 0.388113337549528 0.895797227421048 0.868957410079128 0.906645475357619
0.514726870663309 1.37194840648291 1.17901149918237 0.267171163532900 0.679251749599892
0.700833065925187 0.843516259310205 0.692695783390200 0.206484971298492 0.773597719024071
0.748304643154520 0.433574718009251 0.551547292426642 0.346941328685530 0.738716957530404
How can I intigrate it (x = integration(v)dt) in such way that I get the position of x in every time step? I mean, I want x1,x2,x3,x4, and x5 :)
Thank you so much!
  3 Comments
Ashfaq Ahmed
Ashfaq Ahmed on 25 Mar 2022
Yes, you interpreted it right. Those are 7 different person's data. There are NaN values in the problem, but they were some other values (say, 0) how would I do the calculation?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 25 Mar 2022
Edited: Torsten on 25 Mar 2022
After replacing the NaN values in the matrix, just do
T = [5 5.005 5.015 5.020 5.025];
A = [0.223886255942431 0.766594808762019 0.777477860918720 1.46402363417739 0
0 0.666581311838176 0.440897758695197 0.786687514042304 0
0 0.760744913959832 0.726179926996350 1.04378898162688 0.222809516150796
0 0.275556537143772 0.805109395242995 0.500274785771561 1.14165961699158
0 0.388113337549528 0.895797227421048 0.868957410079128 0.906645475357619
0.514726870663309 1.37194840648291 1.17901149918237 0.267171163532900 0.679251749599892
0.700833065925187 0.843516259310205 0.692695783390200 0.206484971298492 0.773597719024071
0.748304643154520 0.433574718009251 0.551547292426642 0.346941328685530 0.738716957530404];
X0 = zeros(size(A,1),1);
for i = 1:size(A,1)
X(i,:) = X0(i) + cumtrapz(T,A(i,:));
end
X

More Answers (0)

Community Treasure Hunt

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

Start Hunting!