
Douglas B. answered 06/05/20
HS and College Math: Clear and to the Point
If you are writing a code with user-defined input, you should use a Matlab function (instead of just a script). You might try something like:
function root = my_fun(input_fun,x0)
%your code goes here
end
,where x0 is the initial guess, and input_fun is a function handle.
To give the tabulated results in a .txt file (assuming the results are the approximate roots for each iteration), you can explore the writematrix function.