Fix error that says invalid first argument

5 Ansichten (letzte 30 Tage)
Aparajita
Aparajita am 23 Nov. 2023
Bearbeitet: Dyuman Joshi am 29 Nov. 2023
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 23 Nov. 2023
Bearbeitet: Dyuman Joshi am 29 Nov. 2023
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 am 29 Nov. 2023
The "plot range" had to be moved to the end of the previous lines

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rangesh
Rangesh am 29 Nov. 2023
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.

Community Treasure Hunt

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

Start Hunting!

Translated by