fmincon to solve constrained optimization problem with a nonlinear constraint
Show older comments
I've got a challenging problem to solve using the fmincon function. I've attached the question and posted the code from the question I solved prior to this one to give you a better idea of what I'm doing. Thanks for your guidance...here's the previous code.
% Used for plotting as it contains both x and y
z2 = @(x,y) (x/(sqrt(x.^2 + y.^2))).*(besselj(1, 3.8316.*sqrt(x.^2 + y.^2)));
% Used for finding min at each function
z0 = @(x) (x(1)/(sqrt(x(1).^2 + x(2).^2))).*(besselj(1, 3.8316.*sqrt(x(1).^2 + x(2).^2)));
% Used to find max at each function due to multiplying by (-1)
z1 = @(x) (-1)*(x(1)/(sqrt(x(1).^2 + x(2).^2))).*(besselj(1, 3.8316.*sqrt(x(1).^2 + x(2).^2)));
% Defining initial conditions
a = [.5, -.5];
% Running min/max search using fminsearch function
[xi,fvali,exitflagi,outputi] = fminsearch(z0, a);
[xa,fvala,exitflaga,outputa] = fminsearch(z1, a);
% Running min/max search using fminunc function
[xi1,fvali1,exitflagi1,outputi1] = fminunc(z0, a);
[xa1,fvala1,exitflaga1,outputa1] = fminunc(z1, a);
% Plotting a max found from the search
hold on
ezmeshc(z2, [-1, 1, -1, 1]);
plot3(xa(1,1),xa(1,2), fvala , 'ob', 'MarkerSize', 12);
axis([-1 1 -1 1 -1 1]); % Expanded the axis to show marker
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
legend('grid', 'rings', 'marker');
view(155, 9); % Adjusting starting orientation of plot
1 Comment
BlkHoleSun
on 18 Nov 2017
Accepted Answer
More Answers (0)
Categories
Find more on Global or Multiple Starting Point Search in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!