plot for fmincon with multiple value of parameter

8 views (last 30 days)
Does any one know how to plot optimal results w.r.t. the value of m, c below my optimisation problem.
Say, I need to plot m at x axis and x(1) at y axis.
f = @(x,m)(-m*x(1)-2*x(2)-x(1)*x(2))
for m=2:0.2:3
[x,fval]=fmincon(@(x)f(x,m),x0,[1,1],18,[],[],[0;0],[Inf;Inf])
end
Thanks

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 8 Jul 2013
I posted the answer in your previous questions here:
  4 Comments
Ni
Ni on 9 Jul 2013
Hi Shashank, could you help on my problem as below, very urgent. I need to plot multiple lines in one graph. The first line is the optimal solution of x(1) with the value a=-0.02 and b=0.05; The second line is the optimal solution of x(1) with value a=-0.05 and b=0.05;
see below the detailed codes of a single line in the graph with one set of a and b.
x0=[0,0,0,0];
m=2;a=-0.02;b=0.05;d=0.9;c=0.05;
f = @(x,r)(-x(1)*x(2)*(m-x(2)-c)-(1-x(1))*x(2)*(m-x(2)+(a+b)/2-c)-d*x(3)*x(4)*(m+x(1)*x(2)+(1-x(1))*x(2)*r-x(4)-c)-d*(1-x(3))*x(4)*(m+x(1)*x(2)+(1-x(1))*x(2)*r-x(4)+(a+b)/2-c))
r=0:0.05:1
for ii = 1:length(r)
x(:,ii),fval]=fmincon(@(x)f(x,r(ii)),x0,[],[],[],[],[0;0;0;0],[1;2;1;2])
end
plot(r,x(1,:))
title('Figure Title');
xlabel('x');
ylabel('y');

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance 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!