Hi,
The error message indicates that the "particleswarm" solver is not compatible with the optimproblem object created. The error suggests that you use a different solver that is compatible with the "optimproblem" object, such as the "fmincon" solver. Here is how you can modify your code to use the fmincon solver:
- Remove the following line that sets the non-default solver options for "particleswarm": "options2 = optimoptions("particleswarm","Display","iter","PlotFcn","pswplotbestf");"
- Update the code that solves the optimization problem by specifying the fmincon solver:
options = optimoptions('fmincon', 'Algorithm', 'active-set', 'Display', 'iter');
[solution,objectiveValue,exitflag] = solve(problem,initialPoint2,'solver','fmincon','options',options);
This code sets options for the fmincon solver and specifies it as the solver to use when calling the "solve" function.
3. Run the modified code and compare the results obtained using the fmincon solver with those obtained using the "particleswarm" solver.
Here is the link to the MathWorks documentation on the "optimoptions" function, which can be used to set solver options in MATLAB:
And here is the documentation on the "fmincon" solver: