Fix error that says invalid first argument
古いコメントを表示
syms x y L
f = input('Enter the function f(x,y): '); % f(x,y)= x*y ; x^2+y^2
g = input('Enter the constraint function g(x,y): '); % g(x,y)= ((x^2)/8)+((y^2)/2)-1 ; x+y-10
F = f + L*g;
gradF = jacobian(F,[x,y]);
[L,x1,y1] = solve(g,gradF(1),gradF(2),'Real',true); % Solving only for Real x and y
x1 = double(x1); y1 = double(y1);
xmx = max(x1); xmn = min(x1); % Finding max and min of x-coordinates for plot range
ymx = max(y1); ymn = min(y1); % Finding max and min of y-coordinates for plot range
range = [xmn-3 xmx+3 ymn-3 ymx+3]; % Setting plot range
ezmesh(f,range);hold on; grid on;
h = ezplot(g,range); set(h,'LineWidth',2);
tmp = get(h,'contourMatrix');
xdt = tmp(1,2:end); % Avoiding first x-data point
ydt = tmp(2,2:end); % Avoiding first y-data point
zdt = double(subs(f,{x,y},{xdt,ydt}));
plot3(xdt,ydt,zdt,'-o','Color','b','MarkerSize',10);axis(range);
for i = 1:numel(x1)
G(i) = subs(f,[x,y],[x1(i),y1(i)])
plot3(x1(i),y1(i),G(i),'*k','MarkerSize',20);
end
title('Constrained Maxima/Minima')
2 件のコメント
Dyuman Joshi
2023 年 11 月 23 日
編集済み: Dyuman Joshi
2023 年 11 月 29 日
Walter Roberson
2023 年 11 月 29 日
The "plot range" had to be moved to the end of the previous lines
回答 (1 件)
Rangesh
2023 年 11 月 29 日
0 投票
Hi Aparjita,
I understand that you want to address the issue of an invalid first argument.
The error is occurring because the plot range is not in a valid syntax. If you comment out that section of the code, it should work fine. It seems like you are attempting to limit the axis of the plot. To achieve this, you can refer to the documentation on how to properly set the plot range:
I hope this resolves your query.
Thanks,
Rangesh.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!