plot for fmincon with multiple value of parameter

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

 채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 7월 8일

0 개 추천

I posted the answer in your previous questions here:

댓글 수: 4

Ni
Ni 2013년 7월 9일
Thanks so much Shashank.
A quick question, I want to plot another optimal solution with different range of m, say m=0:02:2. But I wish to plot two lines in the same picture, namely with the value of m=0:0.2:2 and m=2:0.2:3; x axis is the value of m, y axis is the value of optimal solution x(1).
Ni
Ni 2013년 7월 9일
And, two lines are in different colors.
Tons of thanks Shashank.
You will find all that information for customization right here:
Ni
Ni 2013년 7월 9일
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');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by