Attempted to access T(1,0); index must be a positive integer or logical.

I have to create a toeplitz matrix without using the command. my teacher said to start off with something like this. Its for this problem Write a MATLAB routine (that is, a MATLAB function) that produces the finite difference solution ^u. Use a uniform discretization with x = 1=(n+1). (The input to the function should be n, and the output should be the approximate solution ^u.) Plot the approximate solution against the exact solution for n = 3, 7 and 15.
T(1,1)=1
T(1,2)=-1
for i=1:n-2
T(i,i-1)=1;
T(i,1)=-1;
T(i,i+1)=0;
end
It keeps giving me the error -Attempted to access T(1,0); index must be a positive integer or logical.- Anyone have a better idea of how to create this thing?

 Accepted Answer

When i = 1 (your first iteration), then i-1 equals zero, so you'd have T(1,0). Zero is not allowed as a column number. Start your loop with i=2.

1 Comment

Thanks a lot. It helped me figure out some other problems as well!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!