Error using odearguments line doesn't exist.
3 次查看(过去 30 天)
显示 更早的评论
[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.
0 个评论
回答(1 个)
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 个评论
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!