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

1 回表示 (過去 30 日間)
Kyle
Kyle 2013 年 2 月 6 日
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?

採用された回答

Image Analyst
Image Analyst 2013 年 2 月 6 日
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 件のコメント
Kyle
Kyle 2013 年 2 月 7 日
Thanks a lot. It helped me figure out some other problems as well!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by