Fill a matrix with a while loop and generate a convergence criteria
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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
Respuestas (0)
Ver también
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!