for recursive formula index value

1 回表示 (過去 30 日間)
yogeshwari patel
yogeshwari patel 2021 年 7 月 13 日
回答済み: Prince Kumar 2021 年 8 月 13 日
I was coding the formual
The summation runs for l=0 to k
I write the following code :
syms x
syms a
T=zeros(1,10,'sym')
T(1)=a;
T(2)=0;
for k=2:10
if k==2
A=1
for i=1:k
T(k+2-i)=(-A-(k+2-i)*(k+1-i)*T(k+2-i))/((k-i+1)*(k-i+2));
end
else
A=0
end
end
disp(T)
Here my code is: Now I have asumr T(2) as 0 but when it display T it is showing 2.

回答 (1 件)

Prince Kumar
Prince Kumar 2021 年 8 月 13 日
From my understanding T(2) is getting updated after running the program but you have assumed T(2) to be 2 at the staring of the program.This might be because in this line
for i=1:k
T(k+2-i)=(-A-(k+2-i)*(k+1-i)*T(k+2-i))/((k-i+1)*(k-i+2));
end
you are changing T(2) for i=2 and k=2.
Hence T(2) is getting updated from 0 to some other value.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by