How can I graph this Lagrange Equation?
이전 댓글 표시
My code works and gives results, but there is a problem with the graph, it is blank, how can I fix it?
syms x1 x2 x3 y1 y2 lambda
g = x1+x2+x3+y1+y2 - 10;
L = 12*x1-x1^2+8*x2-x2^2+18*x3-3*x3^2+24*y1-y1^2+10*y2-5*y2^2+lambda*g;
Lx1 = diff(L,x1);
Lx2 = diff(L,x2);
Lx3 = diff(L,x3);
Ly1= diff(L,y1);
Ly2= diff(L,y2);
Llambda = diff(L,lambda);
s = solve([Lx1,Lx2,Lx3,Ly1,Ly2, Llambda])
Lopt = subs(L,[x1,x2,x3,y1,y2,lambda],[s.x1,s.x2,s.x3,s.y1,s.y2,s.lambda])
%solution is over. lets make a graph.
drawingrange=[-10,10];
fig=figure;
hold on;
set(fig,'defaultLineLineWidth',5);
axis equal;
%2D graphs
fcontour(Lopt,drawingrange);
h=gplot(g,drawingrange);
fprintf('number of solutions:%i\n', size(s.lambda,1));
for i=1:size(s.lambda,1)
fprintf('x1%i, x2%i, x3%i, y1%i, y2%i, lambda%i: %f\t;%f\t;%f\t;%f\t;%f\t;%f\t',...
i,i,i,i,i,i,double(s.x1(i)),double(s.x2(i)),double(s.x3(i)),...
double(s.y1(i)),double(s.y2(i)),double(s.lambda(i)))
end

댓글 수: 1
Torsten
2022년 10월 27일
How do you want to plot a function that depends on 5 or 6 independent variables ?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!