MATLAB Answers


Why am I getting the error "Array indices must be positive integers or logical values."?

Yogesh Pai さんによって質問されました 2018 年 12 月 5 日
最新アクティビティ Yogesh Pai さんによって 編集されました 2018 年 12 月 6 日
I want to compare the exponential of matrix A obtained by the summation formula and the one with the eigen values. However, I'm getting the following error when exponential is computed with the diagonalised form (E here).
"Array indices must be positive integers or logical values."
A = [1,2,1,3; 3,1,2,0; 2,2,1,4; 1,3,2,1];
[V,D] = eig(A);
exp_A = 0;
for k = 0:100
exp_A = exp_A + (A^k)/factorial(k);
E = V*(exp(D))\V;

  1 件のコメント

to be frank I didnt get any error running your code

サインイン to comment.


1 件の回答

Answer by Kelly Kearney
on 5 Dec 2018
 Accepted Answer

My guess is you have a variable named eig sitting in your workspace. So when you try to call the eig function, the variable is overshadowing it and matlab is trying to extract the 1st, 2nd, 1st, 3rd, etc. elements from the eig array. The attempt to extract the 0th element leads to the error.
Always be careful with your choice of variable names!

  1 件のコメント

You were right. There was an old value stored in a variable 'exp'. Thanks!

サインイン to comment.

Translated by