2

I am using Octave on Linux to do some basic Matlab computations and I am getting the error mentioned in the title for the following piece of code:

for a = i:n
 aux = U(j,a)/U(a,a);
 % L(a,i) = aux;
end

I would like to mention that U is an n by n matrix and i is the index from another outer loop.

Thanks, Daniel.

Shai
  • 111,146
  • 38
  • 238
  • 371
Daniel
  • 179
  • 2
  • 9

2 Answers2

9

Using i and j as indices in Matlab is not a good practice, since by default they represent sqrt(-1). It would seem like either i or j are not initialized in your code, hence taking their default complex value.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • 1
    Yes, and more complex than what I found out by myself. Thanks for the info! :) – Daniel Dec 13 '12 at 12:56
  • I did not intend to repost the answer, found it out by trial but your answer is much more complete :) Thanks :D – Daniel Jan 14 '13 at 12:25
5

But you don't tell us what j is...

Is it possible there might be a problem with j as an index?

Note that both i and j are defined as sqrt(-1) by default. So if you use j as you have with no explicit predefinition, then you get a complex value, which fails to work as an index.

Shai
  • 111,146
  • 38
  • 238
  • 371