Hi, so I'm trying to optimize a Rosenbrock function such that the function value should be 108.32 and I need to find the value of x1 and x2.
Rosenbrock function is defined as:
f=100*(x2 - x1^2)^2 + (1 - x1)^2
according to the definition of the function x1 and x2 have a minimum values of 1 for f=0. What I need is the value of x1 and x2 so that my function is f=108.32. The code I have so far is:
rosenbrock = @(x)100*(x(:,2) - x(:,1).^2).^2 + (1 - x(:,1)).^2;
x = optimvar('x',1,2);
obj = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
prob = optimproblem('Objective',obj);
cons1 = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2 ==108.32
cons2 = x(2)>=1;
cons3 = x(1)>=1 ;
prob.Constraints.circlecons1 = cons1;
prob.Constraints.circlecons2 = cons2;
prob.Constraints.circlecons3 = cons3;
x0.x = [0 0];
[sol,fval,exitflag,output] = solve(prob,x0)
The thing is the function isn't able to converge and this is the result I'm getting:
((100 .* (x(2) - x(1).^2).^2) + (1 - x(1)).^2)
subject to circlecons1:
((100 .* (x(2) - x(1).^2).^2) + (1 - x(1)).^2) == 108.32
subject to circlecons2:
x(2) >= 1
subject to circlecons3:
x(1) >= 1
Solving problem using fmincon.
Converged to an infeasible point.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance but constraints are not
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
struct with fields:
x: [-0.3960 -0.8745]
struct with fields:
message: '↵Converged to an infeasible point.↵↵fmincon stopped because the size of the current step is less than↵the value of the step size tolerance but constraints are not↵satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization stopped because the relative changes in all elements of x are↵less than options.StepTolerance = 1.000000e-10, but the relative maximum constraint↵violation, 1.746622e-02, exceeds options.ConstraintTolerance = 1.000000e-06.↵↵'
Clearly the second and third constraints aren't being satisfied in this solution x: [-0.3960 -0.8745]. Any ideas on what I should do? BTW I already know that the solution I'm supposed to get is x: [0.6 1.4] for this particular solution, but I need to make a matlab code so I can solve for other data points.