Info

この質問は閉じられています。 編集または回答するには再度開いてください。

matlab 'Index exceeds array boundaries'

1 回表示 (過去 30 日間)
alsgud qor
alsgud qor 2020 年 4 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
by this code, that error happens...and i dunno why...
function H12 =H1(t,X)
m=10;
c=1000;
k=100000;
e=0.001;
w=100;
R=0.5;
X=R*cos(w*t);
Y=R*sin(w*t);
F1=m*e*w^2*cos(w*t);
F2=m*e*w^2*sin(w*t);
H12=[X(2); -c/m*X(2)-k/m*X(1)+F1/m];
end
--------------------------------------------------------
t=0:0.1:20;
X0=[0,0];
>>
[t,X]=ode45(@H1,t,X0);
  2 件のコメント
madhan ravi
madhan ravi 2020 年 4 月 19 日
編集済み: madhan ravi 2020 年 4 月 19 日
What’s X(2) ? Will you post the latex form of the equation?
alsgud qor
alsgud qor 2020 年 4 月 19 日
編集済み: alsgud qor 2020 年 4 月 19 日
It s a second derivate form...um..I think I misunderstood that matlab automatically understood that thing...also X(1) is equal to X's first derivate..I put
X(1)=diff(X);
X(2)=diff(X(1));
in that function and it s still ain't working...

回答 (1 件)

Devineni Aslesha
Devineni Aslesha 2020 年 4 月 21 日
編集済み: Devineni Aslesha 2020 年 4 月 21 日
In the given code, the initial conditions are passed to 'ode45' from the variable 'X0' which is a vector. The 'X0' values are taken by the variable 'X' to obtain the ode solver output. However, in the code, the variable 'X' is modified in such a way that it becomes a scalar value due to which the error occurs. The error can be resolved by not modifying the variable 'X' in the function definition.
I would like to know why the variable 'X' has to be modified in the function definition.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by