Error using odearguments line doesn't exist.

조회 수: 3 (최근 30일)
David Scidmore
David Scidmore 2021년 5월 8일
댓글: Walter Roberson 2021년 5월 8일
[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
plot (T,Y(:,1),'b','linewidth',1)
function dy1 = Bqfun1(t,y)
dy1 = zeros(2,1);
dy1=[y(2)];
y(3)
-3*y(3)-3*y(2)-y(1)-4*sin(t);
end
Error using odearguments (line 95)
BQFUN1 returns a vector of length 1, but the length of initial conditions vector is 3. The vector returned by BQFUN1 and
the initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Test4 (line 1)
[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
What the heck does this even mean? I dont have a line 95.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 5월 8일
[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
That passes in three boundary conditions.
dy1 = zeros(2,1);
That hints you are expecting to output two boundary values
dy1=[y(2)];
But then you overwrite the variable with a scalar
y(3)
and display the third boundary condition
-3*y(3)-3*y(2)-y(1)-4*sin(t);
and calculate something and throw away the result of the calculation.
I would suggest that you misplaced the ]
  댓글 수: 2
David Scidmore
David Scidmore 2021년 5월 8일
Thanks,I've changed it to dy1 = [y(2);
Now it's saying I have an illegal use of end, but if i remove it it says I neeed the end.
Walter Roberson
Walter Roberson 2021년 5월 8일
I said you misplaced the ] not that you should not have it.
[T,Y] = ode45(@Bqfun1,[0 2],[1 1 -0.01]);
plot (T,Y(:,1),'b','linewidth',1)
function dy1 = Bqfun1(t,y)
dy1 = zeros(2,1);
dy1=[y(2);
y(3)
-3*y(3)-3*y(2)-y(1)-4*sin(t)];
end

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by