for loop label/arguement
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 18 de Abr. de 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 comentarios
Sara Ismail-Sutton
el 19 de Abr. de 2021
Steven Lord
el 19 de Abr. de 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
el 19 de Abr. de 2021
Walter Roberson
el 19 de Abr. de 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
el 21 de Abr. de 2021
Walter Roberson
el 21 de Abr. de 2021
Your mu appears to be non-scalar.
Sara Ismail-Sutton
el 21 de Abr. de 2021
Walter Roberson
el 21 de Abr. de 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
el 21 de Abr. de 2021
Walter Roberson
el 22 de Abr. de 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
Categorías
Más información sobre Particle & Nuclear Physics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!