for loop label/arguement
Show older comments
Need to iterate over the bifurcation map n_trans time (n_trans specified above), this is the relevant bit of the code for my question.. which is pretty basic.. what is wrong with the below? I get the error message
"Error in solution: Line: 25 Column: 20
Invalid array indexing."
(no longer line 25 ofc...)
many thanks
x(1)=0.5;
for j=2:(n_trans-1)
x(j+1)=mu*x(j)(1-x(j));
end
Answers (1)
Walter Roberson
on 18 Apr 2021
That looks suspiciously like an Octave message rather than a MATLAB message...
x(j+1)=mu*x(j)(1-x(j));
^^
MATLAB has no implied multiplication, not anywhere -- not even inside the binary language of the moisture vaporators.
10 Comments
Sara Ismail-Sutton
on 19 Apr 2021
Steven Lord
on 19 Apr 2021
You need to explicitly include * between two terms if you want to multiply.
x = 5;
y = 3*x % works
y = 3x % does not work
z = xy % does not work
Sara Ismail-Sutton
on 19 Apr 2021
Walter Roberson
on 19 Apr 2021
Yes it is. It is seeing variable(index)(index) and saying that you cannot do two () index operations in a row.
Sara Ismail-Sutton
on 21 Apr 2021
Walter Roberson
on 21 Apr 2021
Your mu appears to be non-scalar.
Sara Ismail-Sutton
on 21 Apr 2021
Walter Roberson
on 21 Apr 2021
We do not have your complete source code. But if j is non-scalar then x(j-1) would be non-scalar and x(j-1)*(1-x(j-1)) would be an error unless j-1 is a square matrix, in which case you would get a result the same size as j-1 . But that would be fine for storing into x(j) . So the problem is not the j, and must be the mu. For example mu might be empty.
Sara Ismail-Sutton
on 21 Apr 2021
Walter Roberson
on 22 Apr 2021
for i=mu_min:mu_max
Should be
for i=1:n_mu
and
x(j)=mu*x(j-1)*(1-x(j-1));
should refer to mu(i)
Possibly some output should stored indexed at i
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!