Integrate 61 x 3 tabular data using Runge Kutta
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
This method also works to integrate velocity inside the loop before all data's is stored ? I used for loop to compute v1, v2 and v3.
Thanks a lot
I am glad to be of help.
Yes, you can also use a for-loop to integrate the velocity values.
%I've tried to use the program inside the for loop and it gives me the following error. Thanks agian
Error using odearguments (line 21)
When the first argument to ode45 is a function handle, the tspan argument must have at
least two elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in MainPRS20200405 (line 251)
[~,x1] = ode45(@(t,x) odeFun(t, x, time, vvx), time, 0);
Can you show your code?
%vector v runs inside the for loop which is indexed by k
t=1:delt:1;
for k=1:length(t)
v(:,k)=[4*cos(2*pi*t(k));4*sin(2*pi*t(k));10*cos(2*pi*t(k))]*0;%Jv*dgc;
vx(k)=v(1,k);
vy(k)=v(2,k);
vz(k)=v(3,k);
time = 0:0.016:0.016*(numel(vx)-1);
IC = 0; % initial displacement is 0
[~,x1] = ode45(@(t,x) odeFun(t, x, time, vx), time, 0);
[~,x2] = ode45(@(t,x) odeFun(t, x, time, vy), time, 0);
[~,x3] = ode45(@(t,x) odeFun(t, x, time, vz), time, 0);
end
No, this is not the correct approach. Why do you want to write a for-loop like this? What is the goal here?
Actually the code here with me is much complicated than the above. So, I sent you simpler one to show what I am doing . Here is the acutal problem I wanted to solve. Matrix G is made of
. So
must be integrated to run the next loop and update G. Thats what I want.
Thanks you
t=1:0.016:1;
for k=1:length(t)
.
.
.
G=inv(Jq)*Gx;
detR(k)=det([[G(1:3,:)];[G(4:6,:)]]'); % Determinant
v(:,k)=[4*cos(2*pi*t(k));4*sin(2*pi*t(k));10*cos(2*pi*t(k))]*0;%Jv*dgc;
w(:,k)=[-sin(2*pi*t(k)); cos(2*pi*t(k));sin(2*pi*t(k))]*10;
st=[vx(k);vy(k);vz(k);wx(k);wy(k);wz(k)];
MotionModifierM=[eye(6)-transpose(G(7:9,:))*pinv((transpose(G(7:9,:))))];
sta=MotionModifierM*st;%([eye(6)-transpose(G(7:9,:))*pinv((transpose(G(7:9,:))))]*st(:,k)); % modfied velocity
dq(:,k)=G*sta;
dd1(k)=dq(1,k);
dd2(k)=dq(2,k);
dd3(k)=dq(3,k);
time = 0:0.016:0.016*(numel(vx)-1);
IC = 0; % initial displacement is 0
[~,x1] = ode45(@(t,x) odeFun(t, x, time, dd1), time, 0);
[~,x2] = ode45(@(t,x) odeFun(t, x, time, dd2), time, 0);
[~,x3] = ode45(@(t,x) odeFun(t, x, time, dd3), time, 0);
end
You cannot use ode45 like that. The code I have written in my answer requires you to have all the values in the elements in a vector. Why don't you first calculate all the values of v and w and then apply ode45.
I used your code to integrate v and w. But I still have to integrate dq(:,k) that should be used to update G in each iteration. Thats why I cameup with the new question. I integrate dq using Euler's integrartion but integration of v& w with Rung Kutta and integration of dq with Eulers should be compared to check the error . However, I felt it is not possible to get proper error with diffeent integrtion method.
Can you show you actual equations in mathematical form?
Yes, you can share that too.
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.
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
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
댓글 수: 1
Thank you!
카테고리
도움말 센터 및 File Exchange에서 Runge Kutta Methods에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
