Fill a matrix with a while loop and generate a convergence criteria

7 visualizaciones (últimos 30 días)
Lennard Schulze
Lennard Schulze el 27 de Jul. de 2020
Editada: Lennard Schulze el 28 de Jul. de 2020
Hello,
i have a problem with loops and matrices. I want to program an iteration with a while loop where i calculate several values which depend on each other. One value act's as a convergence criterium and therfore i thought it would be smart to store it in a matrix. My problem now is that i don't know how i get the current and the previous value from the matrix. With these two values i want to check the convergence criterium each iteration. (The iteration process is for the analytical calculation of a knurled press connection)
myMatrix = [1,1]; % create matrix
while diff > 1
% here are the calculations
.
.
.
.
p_v = F_rad/(2 * pi * r_ai * l_f); % calculation for the convergence criterium
for
reslut_0 = Matrix(end,end); % second last value
myMatrix = [myMatrix, p_v]; % expand matrix
result_1 = Matrix(end,end); % last value
diff = result_1 - result_0;
end
end
I thought it would be clever to do the convergence check with a for loop. But honestly i don't know which condition it should apply. Maybe anyone could help me out. I saw through the documentation but it didn't really helped me.
Thanks in advantage
  2 comentarios
Stijn Haenen
Stijn Haenen el 27 de Jul. de 2020
I think you should change to order of your code to:
reslut_0 = Matrix(end,end); % second last value
myMatrix = [myMatrix, p_v]; % expand matrix
result_1 = Matrix(end,end); % last value
Lennard Schulze
Lennard Schulze el 28 de Jul. de 2020
Okay thanks for that advice. Is the whole storage operation with the matrix correctly listed?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by