필터 지우기
필터 지우기

ode45 help!!

조회 수: 1 (최근 30일)
Anna Zito
Anna Zito 2020년 9월 22일
답변: madhan ravi 2020년 9월 22일
I am trying to use the ode45 command, but I keep receiving error codes. I have changed so many things but I can not get it to work.
I want to plot the following:
  • the position of the table and its velocity versus time for two or three periods.
  • the velocity versus position.
Here is my current code along with the error messages:
function dx=project1(t,x)
m=20;
M=500;
k=50000;
l=2;
g=9.81;
wn=sqrt(4*k/(m+M));
T=(2*pi)/wn;
x0=-(m*g)/(4*k);
x0dot=-((m)/(m+M))*sqrt(2*g*l);
t=0:0.001:2*T;
xi=x0;
xidot=x0dot;
[t,x]=ode45(@project1, t, [xi xidot]);
figure;
plot(t,x(:,1));
xlabel('time');
ylabel('position');
figure;
plot(t,x(:,2));
xlabel('time');
ylabel('velocity');
function xdot=project1(~,x)
xdot1=x(2);
xdot2=-wn*wn*x(1);
xdot=[xdot1, xdot2];
end
end
----------------------------------------------------------------------------------------------------------------------
Error Message:
Error using odearguments (line 93)
PROJECT1/PROJECT1 must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in project1 (line 23)
[t,x]=ode45(@project1, t, [xi xidot]);

답변 (1개)

madhan ravi
madhan ravi 2020년 9월 22일
Just make the following changes in your code:
function dx = project
xdot = [xdot1; xdot2];

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by