The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Index out of bounds error
Replies: 4   Last Post: Feb 6, 2013 2:32 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 9,850
Registered: 6/7/07
Re: Index out of bounds error
Posted: Feb 5, 2013 7:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/5/2013 3:32 PM, Nicholas wrote:
> I was curious if you could figure out why I am getting an index out of
> bounds error. ...

> Nx = input('Designate number nodes: ');
> u = ones(1,Nx); %initial condition
> for tstep = 1:Nt
> u_o = u;
> d(1:Nx) = (1+nu); %diagonal

a(1:Nx-1) = (-nu/2); %lower diagonal
> c(1:Nx-1) = (-nu/2); %upper diagonal
> for i=2:Nx-1
> b(i) = (1-nu)*u_o(i) + (nu/2)*u_o(i-1) + (nu/2)*u_o(i+1);
> end


From your followup posting...

> The inputs are 51 nodes and 560 time steps
> error:
> Attempted to access u_o(51); index out of bounds because numel(u_o)=50.
> Error in hw3_CN (line 35)
> b(i) = (1-nu)*u_o(i) + (nu/2)*u_o(i-1) + (nu/2)*u_o(i+1);

Well, superficially it looks as though if that were the case numel(u_0)
would be 51, not 50 in the error message so one must presume either
it's not the code posted, precisely, or the inputs aren't as described.


debug on error

and then you can see what's going on when it aborts and the problem will
likely become embarrassingly clear (coding or input errors frequently
are self-humbling :) ).


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.