Input argument contains an empty equation or variable.
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to build an mlapp for lagrange's multiplier. I need to solve a system of equations to get the value of x,y,z. So, This is the code for solving.
syms x y lambda;
f=app.Function1EditField.Value;
func=str2sym(f);
g=app.Constrain1EditField.Value;
cons=str2sym(g);
L = func + lambda*lhs(cons);
%L=str2sym(l);
dL_dx=diff(L,x)==0;
dL_dy=diff(L,y)==0;
dL_dlambda=diff(L,lambda)==0;
system = [dL_dx; dL_dy; dL_dlambda];
[x_val, y_val,lambda_val] = solve(system, [x y lambda], 'Real', true);
the code doesn't show any error when I use it normally, outside the matlab gui code. But when I run the above code I get an error saying:
Error using sym/solve>getEqns
Input argument contains an empty equation or variable.
[eqns,vars,options] = getEqns(varargin{:});
please help!!
3 comentarios
Walter Roberson
el 24 de Feb. de 2023
put a breakpoint at the line
L = func + lambda*lhs(cons);
and execute. When it gets there show us func and cons
Respuestas (1)
Sarthak
el 7 de Mzo. de 2023
Hi,
The error message suggests that one of the equations in your system is empty or contains an empty variable. This can happen if the user does not provide a valid input for the function or constraint, resulting in an empty symbolic expression.
To fix this error, you can add some input validation to your code to ensure that valid expressions are entered by the user. For example, you can check that the input function and constraint are non-empty before proceeding with the Lagrange multiplier calculation:
f = app.Function1EditField.Value;
if isempty(f)
error('Please enter a valid function.');
end
g = app.Constrain1EditField.Value;
if isempty(g)
error('Please enter a valid constraint.');
end
func = str2sym(f);
cons = str2sym(g);
Refer to the ‘isempty()’ documentation below:
0 comentarios
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!