Score critical point on the surface - Matlab

Asked

Viewed 76 times

0

I am making this script to mark the critical point on the surface, only it is giving error : "Error in teste2 (line 26) Plot(Xs(1),Xs(2),'r*')", someone can help me?

clc
clear
H=[2 -2;-2 4];
f=[-4;0];
A=[2 1;1 -4];
b=[6; 0];
lb=zeros(2,1);
ub=[];
[xs,fval,flag] = quadprog(H,f,A,b,[], [], lb, ub, [])

fprintf('%s ', 'Convergente: ')
if flag >0
fprintf('%s \n', 'OK')
disp('Solução obtida:')
xs;
else
fprintf('%s \', 'Não convergente!')
end

x = [0:0.01:5];
y = [0:0.01:5];
[X,Y] = meshgrid(x,y);
Z = -4.*X + X.^2 - 2.*X.*Y + 2.*Y.^2;      %função objetivo
meshc(X,Y,Z)
hold on
plot(xs(1),xs(2),'r*')
hold on
  • Has not xs declared nowhere in the programme.

  • where and how it should declare ?

  • The xs is stated in the right way, because he is the exit from the function quadprog stress-free!

  • @Viniciussouza This script worked ok for me. I only recommend using plot3(xs(1),xs(2),-4.*xs(1) + xs(1).^2 - 2.*xs(1).*xs(2) + 2.*xs(2).^2,'g*') to point at the coordinate z right. If you have something else in debug make comments or edit the question I or someone else may have more luck.

  • 1

    @Guto worked now, thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.