Array indices must be positive integers or logical values.

12 ビュー (過去 30 日間)
Mirza Sadewa
Mirza Sadewa 2021 年 1 月 18 日
コメント済み: Mirza Sadewa 2021 年 1 月 18 日
im sorry i dont know how this can happen, can someone help me
k=[0:20:1000]
for a=1:length(k);
derivative_x(a)=2*kons_G*rho_model*t*(-(1/(z2((x(a)-x0)^2/z2^2+1)))+(1/(z1((x(a)-x0))^2/z1^2+1))); %sudah dalam mGal
derivative_z(a)=((-2*kons_G*t*rho_model*((x(a)-x0)/(z1^2+(x(a)-x0)^2)))); %sudah dalam mGal
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 18 日
derivative_x(a)=2*kons_G*rho_model*t*(-(1/(z2((x(a)-x0)^2/z2^2+1)))+(1/(z1((x(a)-x0))^2/z1^2+1))); %sudah dalam mGal
MATLAB has absolutely no implied multiplication. Not even in the symbolic mathematics languages.
Therefore your z2( and z1( expressions are interpreted as requests to index z2 and z1 at calculated locations that do not happen to come out as positive integers.
  1 件のコメント
Mirza Sadewa
Mirza Sadewa 2021 年 1 月 18 日
thanks, i miss the multiplication in z2( and z1(

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

その他の回答 (1 件)

Jan
Jan 2021 年 1 月 18 日
What is z1 and z2? Are these vectors? Then the message means, that
z2((x(a)-x0)^2/z2^2+1)
is not a valid expression, because (x(a)-x0)^2/z2^2+1 is not a positive integer or logical vector.
You can identify the problem using the debugger. Set a breakpoint in the failing line and evaluate the expression piece by piece:
% 2*kons_G*rho_model*t*(-(1/(z2((x(a)-x0)^2/z2^2+1)))+(1/(z1((x(a)-x0))^2/z1^2+1)))
x(a)
(x(a)-x0)^2
(x(a)-x0)^2/z2^2+1
z2((x(a)-x0)^2/z2^2+1)
... etc

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by