MATLAB: How can we write our values in a column

column

clc
clear all
close all
% f(x) = x^3 - x -3;
% devf(x) = diff(x^3 - x - 3);
Ea = 100;
m = 0;
k = 0;
1i;
x0=(-2-2*i);
display(' k realx imagx abs(f(xk)) ');
while abs(x0^3 - x0 - 3)>10^-5
if m < 50
x1 = x0 - ((x0^3 - x0 - 3) ./ ((3 * x0)^2 - 1));
Ea = abs(((x1 - x0) / x1) * 100);
realx=real(x0);
imagx=imag(x0);
fprintf('%2.0f %12.5f %12.5f %12.5f %12.5f\n', k , realx, imagx, abs(x0^3 - x0 - 3))
k = k + 1;
x0 = x1;
else
break
end
m = m + 1;
end

Best Answer

Your fprintf() format has five %f formats, so it is expecting 5 inputs. However you are only passing four inputs to it. Because of that, the format stops displaying early, before the \n is emitted.
You should remove the last %12.5f from your fprintf.