variable store in loop

1 Ansicht (letzte 30 Tage)
yogeshwari patel
yogeshwari patel am 4 Jan. 2023
Bearbeitet: VBBV am 5 Jan. 2023
syms z x a v
Y(1)=a
T=0
for k=1:2
Y(k+1)=z
v=0
for l=1:k
v=v+kroneckerDelta(sym(l-2))*(k+2-l)*(k+1-l)*Y(k+2-l) % THIS LINE
end
T= v+ 2*(k)*Y(k+1)+(kroneckerDelta(sym(l-2)))==0
a=solve(T,z)
Y(k+1)=a
end
The highlighted part is not getting updated. Why it is so? Y(2)=z is variable and this value is later used to calculate T.

Antworten (1)

VBBV
VBBV am 4 Jan. 2023
syms z x a v
Y(1)=a
T=0
for k=1:2
Y(k+1)=z;
v=0;
for l=1:k
v=v+kroneckerDelta(str2sym('l-2'))*(k+2-l)*(k+1-l)*Y(k+2-l);
end
T= v+ 2*(k)*Y(k+1)+(kroneckerDelta(str2sym('l-2')))==0
a=solve(T,z);
Y(k+1)=a;
end
  6 Kommentare
VBBV
VBBV am 5 Jan. 2023
syms z x a v
Y(1)=a
Y = 
a
T=0;
for k=1:2
Y(k+1)=z
v=0
for l=1:k
v=v+kroneckerDelta(sym(l-2))*(k+2-l)*(k+1-l)*Y(k+2-l) % THIS LINE
end
T= v+ 2*(k)*Y(k+1)+(kroneckerDelta(sym(l-2)))==0
a=solve(T,z)
Y(k)=a % may be this is change needed
end
Y = 
v = 0
v = 
0
T = 
a = 
0
Y = 
Y = 
v = 0
v = 
0
v = 
T = 
a = 
Y = 
VBBV
VBBV am 5 Jan. 2023
Bearbeitet: VBBV am 5 Jan. 2023
you need to assign kth value to a in the below line
a=solve(T,z)
Y(k)=a % may be this is change needed
end

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by