Fix error that says invalid first argument
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Rangesh
2023-11-29
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!