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

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Walter Roberson
Walter Roberson il 19 Nov 2022
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 Commenti
Safia
Safia il 20 Nov 2022
Modificato: Safia il 20 Nov 2022
@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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by