Fill a matrix with a while loop and generate a convergence criteria
7 views (last 30 days)
Show older comments
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 Comments
Stijn Haenen
on 27 Jul 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
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!