function s = GetFBody(I, X) s = '(x(1,1)-1)^2 + (x(2,1)-2)^2 + (x(1,2)-3)^2 + (x(2,2)-4)^2'; S = {'x(1,1)', 'x(1,2)'; 'x(2,1)', 'x(2,2)'}; for i = 1:2 if I(i) s = strrep(s, S{i, 1}, num2str(X(i, 1), 15)); s = strrep(s, S{i, 2}, num2str(X(i, 2), 15)); end end end