I have written some code for some nested for loops that works just fine. It uses a combination of column vectors, row vectors and 3×2 matrices but all the dimensions are consistent. Now when I put these loops in as differential equations and use ode15s, suddenly it won’t work even for a single iteration of t. It says
“Attempted to access MP(2,1); index out of bounds because
size(MP)=[1,6]”
when actually MP is supposed to be a 3×2 matrix, and certainly was when I was testing the code without the ode solver. Does anyone know what is different about the ode solver that results in changing the dimensions of matrices?
Any help would be seriosuly appreciated,
Thanks in advance!
The
oderoutines assume a vector inputy0(1xn) and give a vector outputy. Immediately after the call toode15s, you can convert back to a matrix, using e.g.y = reshape(y,[3 2]);and the rest of your code should work.