isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; if isOctave pkg load optim end; fun = @(x)[ x(5) * 0.1 + x(4) * 0.25 + x(3) * 0.5 + x(2) * 0.25 + x(1) * 0.1 - 0.3; x(6) * 0.1 + x(5) * 0.25 + x(4) * 0.5 + x(3) * 0.25 + x(2) * 0.1 - 0.625; x(7) * 0.1 + x(6) * 0.25 + x(5) * 0.5 + x(4) * 0.25 + x(3) * 0.1 - 0.5; x(8) * 0.1 + x(7) * 0.25 + x(6) * 0.5 + x(5) * 0.25 + x(4) * 0.1 - 0.225; x(9) * 0.1 + x(8) * 0.25 + x(7) * 0.5 + x(6) * 0.25 + x(5) * 0.1 - 0.05; x(10) * 0.1 + x(9) * 0.25 + x(8) * 0.5 + x(7) * 0.25 + x(6) * 0.1 - 0.0]; options = optimset("Display", "iter","FinDiffType" ,"central","MaxIter", 20000, "MaxFunEvals", 40000, "TolFun", 1e-39, "TolX", 1e-39); x0 = [0.5,0.5,0.5,0.5,0.5,0.0,0.0,0.0,0.0,0.0]; lb = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]; ub = [2.9999999999999996,1.2,0.6,1.2,0.5,0.0,0.0,0.0,0.0,0.0]; [x,val] = lsqnonlin(fun, x0, lb, ub, options);