Error in 1st line of code
5 ビュー (過去 30 日間)
古いコメントを表示
Hello. I am new to MATLAB and keep on getting this error every single time:
Error in MSDSOLV (line 1)
[T,Y]= ode45(@MSD,[0 10],[0.3,-0.1]);
This is my MSD code for the differential equations:
function dx=MSD (t,x);
dx=zeroes(2,1);
A=[0 1;-1 -2]
B=[0;1]
J=[-1+i -1-i]
K=acker(A,B,J)
u=-K*[x(1);x(2)]
dx(1)=x(2);
dx(2)=-x(1)-2*x(2)+u;
and this is my solver code for teh differential equations:
[T,Y]= ode45(@MSD,[0:0.1:10],[0.3,-0.1]);
figure(1)
plot(T,Y(:,1),'b')
grid
xlabel('time (s)')
ylabel ('x_1')
Thanks in advance
0 件のコメント
回答 (2 件)
Anudeep Kumar
2025 年 3 月 14 日
Hey Manali,
The issue seems to be in the first line of the definition of “MSD” function.
You have used “zeroes” instead of “zeros” which is the actual defined function in MATLAB. You can make the following change to line 1 of your function definition:
>>dx=zeros(2,1);
Here is the link to the documentation for the function "zeros()" :
Hope that helps!
0 件のコメント
VBBV
2025 年 3 月 15 日
@Manali Kunte, use the limits for time span instead of vector, Besides, there is typo error for function zeroes. The valid Matlab function is zeros
[T,Y]= ode45(@MSD,[0 10],[0.3,-0.1]);
% use the limits for time span instead of vector
figure(1)
plot(T,Y(:,1),'b')
grid
xlabel('time (s)')
ylabel ('x_1')
function dx=MSD (t,x);
dx=zeros(2,1); % use zeros instead of zeroes
A=[0 1;-1 -2];
B=[0;1];
J=[-1+i -1-i];
K=acker(A,B,J);
u=-K*[x(1);x(2)];
dx(1)=x(2);
dx(2)=-x(1)-2*x(2)+u;
end
8 件のコメント
Walter Roberson
2025 年 3 月 16 日
Back in R2012a
>> [T,Y]= ode45(@MSD,0,[0.3,-0.1])
Error using odearguments (line 22)
When the first argument to ode45 is a function handle, the tspan
argument must have at least two elements.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Walter Roberson
2025 年 3 月 16 日
I went through a lot of trouble to install Windows XP and R14. Unfortunately R14 needs PLP, and that needs assistance from Mathworks Support to deal with these days. So I installed R2008a (after notable drama).
>> [T,Y]= ode45(@MSD,0,[0.3,-0.1])
??? Error using ==> odearguments at 24
When the first argument to ode45 is a function handle, the tspan
argument must have at least two elements.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
So if there is an ode45 version that has a problem with tspan that does not have two elements, then it must be before R2008a.
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!