I am trying to make a loglog plot of the secant method. I have ran this exact code below before and it worked fine, and now when I run it today, it's not working anymore.
func = @(x) 2*exp(-2*x) + 4*sin(x) - 2*cos(2*x);
dx = (x2 - x1)*f2/(f2 - f1);
dispdata(:, iter + 1) = [iter;x1;x2];
fprintf('Iteration x1 x2\n')
fprintf('--------------------------------\n')
fprintf('%2d: %7.4f %7.4f\n', dispdata)
y = log(abs(x(3:end) - x(2:end-1)));
x = log(abs(x(2:end-1) - x(1:end-2)));
plot(x, alpha*x + log(lambda))
xlabel('ln|z_{n} - z_{n-1}|')
ylabel('ln|z_{n+1} - z_{n}|')
title(['Y_{n} = ', num2str(alpha), 'X_{n} - ', num2str(lambda)])
legend('Data', 'Fitted line', 'location', 'southeast')
Now I am getting the error message, "The end operator must be used within an array index expression."