필터 지우기
필터 지우기

how to use the result of current iteration as input for next iteration ?

조회 수: 3 (최근 30일)
Safia
Safia 2022년 11월 19일
댓글: Walter Roberson 2022년 11월 20일
hello everyone!
this is my code in matlab, i want to put the result of x_new for the first iteration after doing optimization as input for the next iteration,
for example i have 10 iterations , at first i assign x_new at 0, and after each iteration it will be updated by the new value.
Do you have a suggestion?
x_new=0, %initialize x_new
for l=1: 10 %number of iteration
for i=1:m
for j=1:n
R_lb(i,j)=BP(i,j)*(log2(1+(Puissance(i,j)*(g0/n0(i,j)))/(sqrt(x_new(j)-Pos_c(i,j))^2+H^2))-(Puissance(i,j)*log2(e)*((sqrt(x(j)-Pos_c(i,j))^2)-(sqrt(x_new(j)-Pos_c(i,j))^2))*(g0/n0(i,j)))/((sqrt(x_new(j)-Pos_c(i,j))^2+H^2)*((sqrt(x_new(j)-Pos_c(i,j))^2+H^2)+(Puissance(i,j)*(g0/n0(i,j))))));
end
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2022년 11월 19일
for l=1: 10 %number of iteration
for i=1:m
xnew = zeros(1,n+1);
for j=1:n
R_lb(i,j)=BP(i,j)*(log2(1+(Puissance(i,j)*(g0/n0(i,j)))/(sqrt(x_new(j)-Pos_c(i,j))^2+H^2))-(Puissance(i,j)*log2(e)*((sqrt(x(j)-Pos_c(i,j))^2)-(sqrt(x_new(j)-Pos_c(i,j))^2))*(g0/n0(i,j)))/((sqrt(x_new(j)-Pos_c(i,j))^2+H^2)*((sqrt(x_new(j)-Pos_c(i,j))^2+H^2)+(Puissance(i,j)*(g0/n0(i,j))))));
xnew(j+1) = SomethingAppropriate
end
end
end
  댓글 수: 6
Safia
Safia 2022년 11월 20일
편집: Safia 2022년 11월 20일
@Walter Roberson it seems that you didn't understand my problem, so i will try to explain by this equation attached , it is the same as above but with different notation (just focus on "q" which is in my case "x").
if you notice that i have q(n) and qj(n), the different between them is one is depending on calculation that i did before (i already calculated q(n)), but qj(n) is the new depending on the result of each iteration, because the output after doing calculation will give new q which will be used as input for the next iteration, but q(n) will not change.
at first i should initialize the iteration number(j) and give the value for qj(n)
second, i will do my calculation and a new q*j(n) will be given
third, i will replace the qj+1(n) with q*j(n) , it means i will use the new result of current iteration denoted by q*j(n) for the next iteration (j+1)
and each time i will update.
Walter Roberson
Walter Roberson 2022년 11월 20일
We cannot help you debug code that we cannot see.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by