필터 지우기
필터 지우기

unable to plot 3-d surface with fmincon

조회 수: 5 (최근 30일)
RAHUL KUMAR
RAHUL KUMAR 2019년 8월 21일
답변: Raunak Gupta 2019년 8월 28일
i want to plot 3-D surface ,basically i have two variables (intialguess value) plot with my objective function(fitnessfun).which show something local minima in the plot .Can you give me code suggestion.and i easily plot objective function with iteration . i want with my variables
xo=[0.001,0.005]; % assumptions
%[Q]=heatload1_new(xo)
%nvars=3;
A=[];
b=[];
Aeq=[];
beq=[];
lb=[0.0001,0.003]; %lower bound
ub=[0.01,0.08]; %upper bound
nonlincon = @(x)constraint_new(x); % calling constraint function
Fitnessfun =@(x)weight_testvariable(x); %calling objective function
options = optimoptions(@fmincon,'Display','iter-detailed','Algorithm','sqp','MaxIterations',1500)
options = optimset('Display','iter','TolFun',1e-6)
options = optimset('PlotFcns',@optimplotfval);
[X,fval]=fmincon(Fitnessfun,xo,[],[],[],[],lb,ub,nonlincon,options)

채택된 답변

Raunak Gupta
Raunak Gupta 2019년 8월 28일
Hi,
In my understanding you are trying to visualize the two variables and objective function value with respect to the iterations. The values of variable that are taken in course of optimizing the objective function can be monitored using optimValues parameter.
For plotting the variables with iteration and fval:
  • You can write a Custom plot function using this link. The reference file in the link can show the syntax in which you can get the X(1), X(2), fval and iteration number.
  • This information you can append in three variables and plot fval as color intensity using surf.
  • Try to append the values in current iteration in an array so that you may plot current and previous values also to the surface plot.
  • For every PlotFcns option the .m file is there in MATLAB and you can take help of how to access data in between of iterations.
For Plotting the data in 2D plots:
  • Other way is to plot the 2D curve that contains variables value on one subplot and fval on other subplot with respect to the iterations. This can be done as follow:
options = optimset('PlotFcns',{@optimplotx,@optimplotfval});
If you want to return the outputs so that it may get used later :
  • Return the values of variables and fval that are taken between iterations by writing a custom OutputFcn for which syntax is mentioned here.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by