필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Serbianu
Serbianu 2015년 1월 10일
댓글: Serbianu 2015년 1월 11일
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

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 1월 11일
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
Serbianu
Serbianu 2015년 1월 11일
Thank you a lot, it's working now. I didn't expect to get answered so fast :)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by