Input argument contains an empty equation or variable.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 24 Feb. 2023
put a breakpoint at the line
L = func + lambda*lhs(cons);
and execute. When it gets there show us func and cons
Antworten (1)
Sarthak
am 7 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!