Integrate 61 x 3 tabular data using Runge Kutta

2 次查看(过去 30 天)
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

采纳的回答

Ameer Hamza
Ameer Hamza 2020-5-4
编辑:Ameer Hamza 2020-5-4
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 个评论
Ameer Hamza
Ameer Hamza 2020-5-10
编辑:Ameer Hamza 2020-5-10
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 2020-8-18
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 ?

请先登录,再进行评论。

更多回答(1 个)

darova
darova 2020-5-4
  • 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

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by