フィルターのクリア

maclaurin series code problem

5 ビュー (過去 30 日間)
Mary Jeppson
Mary Jeppson 2016 年 6 月 7 日
コメント済み: Mary Jeppson 2016 年 6 月 7 日
I keep getting "index exceeds matrix dimensions" but i don't see a problem. Can anyone see why this isn't working?
n = 4;
es = 0.5*10^(2-n);
x = 5;
approx(1) = 5;
analytical = sin(5)
et(1) = (analytical-approx(1))/analytical*100
ea(1) = NaN
for k = 1:20
approx(k+1) = approx(k)+(-1)^(k)*x^(2*k+1)/factorial(2*k+1)
ea = (approx(k+1)-approx(k))/approx(k+1)*100
et = (analytical-approx(k+1))/analytical*100
if abs(ea(k+1))<es
break
end
end
I greatly appreciate the help.

採用された回答

Iain
Iain 2016 年 6 月 7 日
abs(ea(k+1))<es
in your code, ea is a scalar, and you're trying to access the k+1th element, which is the error.
  1 件のコメント
Mary Jeppson
Mary Jeppson 2016 年 6 月 7 日
Oh, right. Thank you very much.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by