How would one tablize the iterations from a while loop with the variables at the top?
1 view (last 30 days)
Show older comments
I wrote a fuction that calculates the roots of non-linear equations using a while loop. The function asks for a lower and upper bound calculates "c", the possible root and runs it again. If the following trial is with in a certain specified tolerance then the while loop stops. I am looking to tablize all of the iterations.
I am currently using 'fprintf' to show the values of the loop at each iteration but I would rather to see it in a table, with the values of the upper and lower bounds.
Any help will be greatly appricated.
0 Comments
Answers (1)
Sindar
on 12 Feb 2020
Edited: Sindar
on 12 Feb 2020
something like this will work, but may not be the most efficient depending on the number of iterations:
tol = 1e-5;
c_old = Inf;
bounds = [0 1000];
mytable = table(bounds(1),bounds(2),NaN,'VariableNames',{'low_bound','high_bound','c');
while c_diff > tol
% whatever your process is:
[c,bounds] = calc_roots(bounds);
% add a new row
mytable(end+1,:)={bounds(1) bounds(2) 3};
c_diff = abs(c - c_old);
c_old = c;
end
% print the table
disp(mytable)
0 Comments
See Also
Categories
Find more on Logical 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!