The following code is expected to plot the output of Rosenbrock's function against number of iterations ( for the sake of the problem, don't be concerned with the quality of the source code).
function value = banana(x0) a = x0(1); b = x0(2); x = x0(3); y = x0(4); value = (1 - x + a)^2 + 100 * (y - b * (x - a)^2)^2; end a = int8(4 * rand()) / 2; b = int8(4 * rand()) / 2; [x1, y1] = random(a, b); [x2, y2] = random(a, b);[x3, y3] = random(a, b); [x4, y4] = random(a, b); x = [x1; x2; x3; x4]; y = [y1; y2; y3; y4]; save values.mat; for i = 1 x0 = [a, b, x(i), y(i)]; options = optimset('PlotFcns', { @optimplotfval }); [solution_point, fval,exitflag,output] = fminsearch(@banana,double(x0),options); old_x=[x(i),y(i)]; new_x_1 = linspace(-2,2,51); new_x_2 = linspace(-2,2,51); for j=1:51 if(new_x_1(j)>= old_x(1)) new_x_1(j)=old_x(1); break; end end for j=1:51 if(new_x_2(j)>= old_x(2)) new_x_2(j)=old_x(2); break; end end end
My questions are,
(1) Is this plot really showing the output of Rosenbrock's function against number of iterations?
(2) The plot shows a sudden slump in the output of the function. I need to show this plot in logarithmic form, so that a smooth curve is plotted. How can I do that?
Best Answer