MATLAB: I would like to have fzero display its iterates in format long.

displayfzero

I am doing a convergence rate study for my students, and I have them entering:
f = @(x) 2^x+x;
options = ('Display','iter');
fzero(f,[-1,0],options)
I get the desired table containing the iterates of the fzero algorithm, but I need more precision in those outputs in order to find an approximate convergence rate. Is there a way to change the format on the display?
Thanks!

Best Answer

Okay, I found a solution in MATLAB help documentation for Output functions:
function [x fval history] = conv_rate(x0)
history = [];
options = optimset('OutputFcn', @myoutput);
[x fval] = fzero(@objfun, x0,options);
function stop = myoutput(x,optimvalues,state);
stop = false;
if isequal(state,'iter')
history = [history; x];
end
end
function z = objfun(x)
z = 2^x+x;
end
end