필터 지우기
필터 지우기

Keep getting this error and I cannot figure out why: Dimensions of arrays being concatenated are not consistent.

조회 수: 1 (최근 30일)
I have the following code trying to solve differential equation of second order:
[t,X] = ode45(@(t,X) odefun_4(t,X,u), [0 10], [0;0]);
function dx = odefun_4(t,x,u)
%xdisp(u);
m = 15;
b = 0.2;
k = 2;
%u = interp1(ut,u,t);
dx = [x(2); u/m - (b/m)*x(2) - (k/m)*x(1)];
end
Vector u is a 1x100 vector. I expect to get a 2x100 matrix as the return value. What am I doing wrong ?

채택된 답변

madhan ravi
madhan ravi 2018년 11월 11일
편집: madhan ravi 2018년 11월 11일
EDITED
m = 15;
b = 0.2;
k = 2;
ut = linspace(0, 10);
u = 5 * sin(2 * ut) + 10.5; % input of our system - external forc
dx = @(t,x,u)[x(2); u/m - (b/m)*x(2) - (k/m)*x(1)]
for u=u
[t,X] = ode45(@(t,x)dx(t,x,u), [0 10], [0;0]); %function calling
plot(t,X)
hold on
end
  댓글 수: 11
madhan ravi
madhan ravi 2018년 11월 11일
편집: madhan ravi 2018년 11월 11일
Anytime :) make sure to accept the answer so that people know the question is solved

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by