How would one tablize the iterations from a while loop with the variables at the top?
이전 댓글 표시
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.
답변 (1개)
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)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!