how do i get a contour plot for this code?

조회 수: 4 (최근 30일)
Aishwarya Bangalore Kumar
Aishwarya Bangalore Kumar 2018년 2월 14일
댓글: Aishwarya Bangalore Kumar 2018년 2월 14일
This is my code and I'm trying to get a contour plot for it. But I am not getting it. Can anyone help me
f=@(x,y) sin(x)+cos(y);
x0 = [5.5,5.5];
options = optimoptions('fminunc','Display','iter ','Algorithm','quasi-newton');
[opt, opt_cost]=fminunc('hw2pr2_cost',x0,options);
lb = (pi/2); ub = (2*pi);
options = optimoptions('fmincon','Display','iter','Algorithm','active-set');
[optx_con, opt_costcon] = fmincon('hw2pr2_cost',x0,[],[],[],[],lb,ub,'hw2pr2_constraint',options);
fcontour(f);
hold on
plot(opt(1),opt(2),'ko');
%contour(y,y,'ko');
hold on
plot(optx_con(1),optx_con(2),'ko');
%contour(y,y,'ko');
y=-x;
hold on
plot(x,y);
  댓글 수: 17
Walter Roberson
Walter Roberson 2018년 2월 14일
Yes, you should assign a value to x before running that code. It is not at all clear what you are expecting, though. Are you trying to plot a 45 degree angle from top left to bottom right? If so then there are other ways of doing that.
your plot(x,y) is not going to be a contour plot. fminunc() and fmincon() are going to return vectors of length 2 that you are plotting as individual points on top of the fcontour() result. The function you are plotting through fcontour() has nothing obvious to do with whatever hw2pr2_cost does.
Aishwarya Bangalore Kumar
Aishwarya Bangalore Kumar 2018년 2월 14일
got it thank you sir.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by