Fix error that says invalid first argument

조회 수: 3 (최근 30일)
Aparajita
Aparajita 2023년 11월 23일
편집: Dyuman Joshi 2023년 11월 29일
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
Dyuman Joshi 2023년 11월 23일
편집: Dyuman Joshi 2023년 11월 29일
What do you expect this line of code to do? What is the idea behind it?
[L,x1,y1] = solve(g,gradF(1),gradF(2),'Real',true); % Solving only for Real x and y
Edit - ezplot is not recommended to use. Use fplot instead.
Walter Roberson
Walter Roberson 2023년 11월 29일
The "plot range" had to be moved to the end of the previous lines

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

답변 (1개)

Rangesh
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by