Error using odearguments line doesn't exist.

5 views (last 30 days)
[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.

Answers (1)

Walter Roberson
Walter Roberson on 8 May 2021
[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 Comments
David Scidmore
David Scidmore on 8 May 2021
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 on 8 May 2021
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

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!