フィルターのクリア

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.
  1 件のコメント
Sena
Sena 2022 年 11 月 13 日
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by