Effacer les filtres
Effacer les filtres

Input argument contains an empty equation or variable.

4 vues (au cours des 30 derniers jours)
Nittya Ananda
Nittya Ananda le 23 Fév 2023
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.
Error in sym/solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
please help!!
  3 commentaires
Nittya Ananda
Nittya Ananda le 24 Fév 2023
This is my interface, nothing is showing up in the output.
Walter Roberson
Walter Roberson le 24 Fév 2023
put a breakpoint at the line
L = func + lambda*lhs(cons);
and execute. When it gets there show us func and cons

Connectez-vous pour commenter.

Réponses (1)

Sarthak
Sarthak le 7 Mar 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:

Catégories

En savoir plus sur Modeling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by