Borrar filtros
Borrar filtros

Got an error using ode45 - FUNC1 must return a column vector

1 visualización (últimos 30 días)
Serbianu
Serbianu el 10 de En. de 2015
Comentada: Serbianu el 11 de En. de 2015
Script looks like this :
clear all
clc
x0=[7 10 13];
tspan=[0,10];
[t,x]=ode45(@func1,tspan,x0);
subplot(3,1,1);
hold on;
plot(t,x(:,1),'k');
subplot(3,1,2);
hold on;
plot(t,x(:,2),'k');
subplot(3,1,3);
hold on;
plot(t,x(:,3),'k');
and Function :
function xd = func1( t,x )
xd(1)=2*x(1)+3*x(2)-4*x(3);
xd(2)=-x(1)+2*x(2);
xd(3)=(-2)*x(1)+x(2)+2;
end

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 11 de En. de 2015
Serbianu - the error message is telling you that the function func1 must return a column vector. From your code, the vector xd is a row vector. So just change this to a column vector as
function xd = func1( t,x )
xd = zeros(3,1);
xd(1)=2*x(1)+3*x(2)-4*x(3);
xd(2)=-x(1)+2*x(2);
xd(3)=(-2)*x(1)+x(2)+2;
end
In the above, we've added a line that just initialized xd as a column vector with three elements. Try making the change and see what happens!
(An alternative solution would be just to transpose the vector xd.)
  1 comentario
Serbianu
Serbianu el 11 de En. de 2015
Thank you a lot, it's working now. I didn't expect to get answered so fast :)

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by