# Error using odearguments line doesn't exist.

1 visualizzazione (ultimi 30 giorni)
David Scidmore il 8 Mag 2021
[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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Walter Roberson il 8 Mag 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 CommentiMostra NessunoNascondi Nessuno
David Scidmore il 8 Mag 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 il 8 Mag 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

Accedi per commentare.

### Categorie

Scopri di più su Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by