Help with a ode45 problem

2 ビュー (過去 30 日間)
Esteban
Esteban 2012 年 12 月 1 日
Hi
I have the following function:
function f=matpendel(t,u,g,l,m,c)
f=[u(2)
-g/l*sin(u(1))-c/m*u(2)];
And I'm trying to plot this:
clf;
g=9.82; l=0.1; m=0.1; c=0.2; theta(0)=[10:30:130]*pi/180;
tspan=linspace(0,1,200);
for k=1:length(theta0)
u(0)=[theta0(k);0];
[t,U]=ode45(@(t,u)matpendel(t,u,g,l,m,c),tspan,u(0));
subplot(1,2,1), plot(t,U(:,1)), hold on
subplot(1,2,2), plot(U(:,1),U(:,2)), hold on
end
But I get the error Subscript indices must either be real positive integers or logicals. Does anybody know why?
  1 件のコメント
Jan
Jan 2012 年 12 月 1 日
The term "10:30:130" does not need additional square brackets. In fact, they only waste time, because this is a vector already.

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 1 日
編集済み: Azzi Abdelmalek 2012 年 12 月 1 日
The error is in
theta(0)=[10:30:130]*pi/180;
do you mean
theta0=
  1 件のコメント
Esteban
Esteban 2012 年 12 月 1 日
編集済み: Esteban 2012 年 12 月 1 日
Ah yes, it is true that I meant theta0 and not theta(0), thanks!
But I still get the same error...
Edit: I changed u(0) to u0 too, now it works. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by