Integrate 61 x 3 tabular data using Runge Kutta

1 view (last 30 days)
I have a 61 x 3 velocity data and wanted to integrate using Rung Kutta integrator? I know how to integrate when I have a function but I am a bit confused when it is tabular data. Integration step is . Data is attached. Any help is apperciated. Thanks

Accepted Answer

Ameer Hamza
Ameer Hamza on 4 May 2020
Edited: Ameer Hamza on 4 May 2020
If you are okay with using the built-in function, then use ode45, which is an implementation of the RK (4,5) algorithm.
data = load('angular.velocity.data.txt');
v1 = data(:,1); % First column
v2 = data(:,2); % Second column
v3 = data(:,3); % Third column
time = 0:0.016:0.016*(numel(v1)-1);
IC = 0; % initial displacement is 0
[~,x1] = ode45(@(t,x) odeFun(t, x, time, v1), time, 0);
[~,x2] = ode45(@(t,x) odeFun(t, x, time, v2), time, 0);
[~,x3] = ode45(@(t,x) odeFun(t, x, time, v3), time, 0);
%% plotting
subplot(1,3,1)
plot(t,v1,t,x1);
legend({'Velocity', 'displacement'})
subplot(1,3,2)
plot(t,v2,t,x2);
legend({'Velocity', 'displacement'})
subplot(1,3,3)
plot(t,v3,t,x3);
legend({'Velocity', 'displacement'})
function v = odeFun(t, x, time, vx)
% v = interp1(time, vx, t, 'linear'); % linear interpolation
% v = interp1(time, vx, t, 'pchip'); % pchip interpolation
v = interp1(time, vx, t, 'makima'); % makima interpolation
end
  13 Comments
Ameer Hamza
Ameer Hamza on 10 May 2020
Edited: Ameer Hamza on 10 May 2020
Value of which variables change with the value of integration? See this example: https://www.mathworks.com/help/releases/R2020a/matlab/ref/ode45.html#bu3l43b to see how to handle parameters which vary with the input variable.
HN
HN on 18 Aug 2020
I need your help in similr problem,
S % 3 by 100 data
W=skew(S) % 4 by 4 marix
dq=0.5*(W*q')'; % have only initial q
I wanted to integrate dq to get q. Can you help me ?

Sign in to comment.

More Answers (1)

darova
darova on 4 May 2020
  • YOu can create function using interp1 or spline
  • You can write your own solver
Simple solver Euler method
for i = 1:length(velocity)
position(i+1) = position(i) + dt*velocity(i);
end

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!