using end value in next iteration

want the Vo at the end of each loop to be used in the start of the next iteration, just can't get to work, I display Vn but its not updating from iteration to iteration. Any thoughts?
%
Voo = [30 15 13 10]; %
while true
%
Vo = Voo;
%
f1 = 64 / Re1;
f2 = 64 / Re2;
f3 = 64 / Re3;
f4 = 64 / Re4;
X = [matrix]
%
Y = [matrix]
Vn = X\Y;
disp(Vn)
%
for i = 1:4
Va(i) = (alpha * Vn(i)) + ((1-alpha) * Vo(i));
Vo(i) = Va(i);
if (abs(Va(1)-Vn(1)))<1e-3
break;
end
end

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 2 Sep 2013
Modifié(e) : Azzi Abdelmalek le 2 Sep 2013

0 votes

Voo = [30 15 13 10];
Vo=Voo
while ~all([Va==Vo,Vo==Vn]) (needs to be approx equal to)
Vo=Voo
Re1 = (D(1).*Vo(1)) / nu;
Re2 = (D(2).*Vo(2)) / nu;
Re3 = (D(3).*Vo(3)) / nu;
Re4 = (D(4).*Vo(4)) / nu;
A = [Matrix];
b = [Matrix];
Vn = A\b;% solves four unknowns at A\b % (1 col, 4 rows)
for i = 1:4
Va(i) = (alpha * Vn(i)) + ((1-alpha) * Vo(i)); %(1 col, 4 rows)
Vo(i) = Va(i); %Used as Vo for each in next iteration. (1 col, 4 rows)
end
end

5 commentaires

thanks Azzi amended code shown above, i get an error, how do i fix this?
??? Undefined function or variable 'Va'.
while ~all([Va==Vo,Vo==Vn])
Azzi Abdelmalek
Azzi Abdelmalek le 2 Sep 2013
What is Va?
harley
harley le 2 Sep 2013
i calculate a new Va with each iteration through Vo, Va calc is 5 lines from the bottom. Not sure how to get around this.
you must initialize Va, also what is:
while ~all([Va==Vo,Vo==Vn])
harley
harley le 2 Sep 2013
i want it to iterate until Va, Vo and Vn converge , so that part needs to be re-written to allow for some tolerance say 0.01.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by