필터 지우기
필터 지우기

How can I graph this Lagrange Equation?

조회 수: 4 (최근 30일)
Sena
Sena 2022년 10월 27일
댓글: Sena 2022년 11월 13일
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
Torsten 2022년 10월 27일
How do you want to plot a function that depends on 5 or 6 independent variables ?

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

채택된 답변

Jayant Gangwar
Jayant Gangwar 2022년 11월 3일
Hi Sena,
"fcontour" function can be used to plot the contour lines of symbolic expression f(x,y), which means that it is suitable to plot a symbolic expression with no more than 2 independent variables, but you are trying to use it to plot an expression with 6 independent variables because of which it is outputting an empty graph.
To visualize your solution, it would require a 6D space which is not possible.
Please refer to this MATLAB answer for more information on how you can visualize your solution by breaking it into parts.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by