how to add for loop within the for loop if indices are depended on each other

1 回表示 (過去 30 日間)
YOGESHWARI PATEL
YOGESHWARI PATEL 2017 年 1 月 5 日
編集済み: Guillaume 2017 年 1 月 5 日
i already posted my question but as i am a new user i could get the answer suggested.so i am again posting my question but i different manner i cut my formula i.e. i eliminate the last term and write the code for the following formula
(h+1)C(k,h+1)=-u(k+1)C(k+1,h)-UC(k,h)+D(k+2)(k+1)C(k+2,h)+Da(summation(r=0 to k)summation(s=0 to h) kroneckerdelta(r-1,h-s)(k-r+1)(k-r+2)C(k-r+2,s)
Kroneckerdelta function is defined as follows
function d = kronDel(i,j)
if i == j
d = 1;
else
d = 0;
end
n=25;
C1=zeros(n+5);
a=0.01;
u=16.5;
U=0.00000037037;
D=0.01;
c1=0.030792;
c2=0.009208;
alpha=0.00000588235;
for i=1:1:n+5
C1(1,1)=c1+c2;
C1(i,1)=(c2*((-alpha)^(i-1))/factorial(i-1));
end
for j=1:1:n+1
for i=1:1:n+1
C1(i,j+1)=(((-u*i*C1(i+1,j)-U*C1(i,j)+D*i*(i+1)*C1(i+2,j)))+a*D* kronDel(i-1,j)*((n+1)-(i)+1)*((n+1)-i+2)*C1(((n+1)-i+2),j))/j;
end
end
The problem part is how to run the summation for delta.As i am getting answer of 1st and 2nd column correctly.But in third column 2 value are correct.For third value two kronecker delta value should be added but it is not happening in my code.So how should be done.
Who ever give answer plz be specific do not just write as i am a new user and i don't have much knowledge of MATLAB.

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by