フィルターのクリア

Using ODE45 on inverted pendulum without external torque

6 ビュー (過去 30 日間)
Jonathan Diaz
Jonathan Diaz 2018 年 9 月 12 日
コメント済み: Stephan 2018 年 9 月 13 日
I have this problem, I'm trying to plot my solutions but there is an error not enough input arguments. The question is in the attached file.
function dx = invpen(t,x)
dx = zeros(2,1); % column vector
dx(1) = x(2);
dx(2) = (1/(1.0*1.0^2))*(1.0*9.8*1.0*sin(x(1)-0.5*x(2)));
[T,X] = ode45(@invpen,[0,20],[30,0]);
plot(T,X(:,1),'-',T,X(:,2),'.')
  1 件のコメント
Jan
Jan 2018 年 9 月 12 日
Is this stored in one file and you start it using the "Start" button of the editor? Then invpen is called without inputs.

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

回答 (2 件)

Stephan
Stephan 2018 年 9 月 12 日
Hi,
use:
[T,X] = ode45(@invpen,[0,20],[30,0]);
plot(T,X(:,1),'-',T,X(:,2),'.')
function dx = invpen(~,x)
dx = zeros(2,1); % column vector
dx(1) = x(2);
dx(2) = (1/(1.0*1.0^2))*(1.0*9.8*1.0*sin(x(1)-0.5*x(2)));
end
The code runs so far - i did not check if it is a meaningful result.
Best regards
Stephan
  3 件のコメント
Jonathan Diaz
Jonathan Diaz 2018 年 9 月 12 日
Nevermind! Thanks!
Stephan
Stephan 2018 年 9 月 12 日
Glad to hear - Please accept helpful answers in order to help other people having similar problems finding helpful answers.

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


Jan
Jan 2018 年 9 月 12 日
Is this stored in one file and you start it using the "Start" button of the editor? Then invpen is called without inputs.
Stephen's suggestion should work. Create a file called "main.m" (or whatever you like) and insert the code. Then you can start this as a script from the command window or with the "Start" button. Defining subfunctions inside scripts works in modern Matlab versions only. For an older version start the "main.m" file with
function main
  3 件のコメント
Jan
Jan 2018 年 9 月 13 日
Stephan
Stephan 2018 年 9 月 13 日
Thank you!

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by