필터 지우기
필터 지우기

Input argument contains an empty equation or variable.

조회 수: 4 (최근 30일)
Nittya Ananda
Nittya Ananda 2023년 2월 23일
답변: Sarthak 2023년 3월 7일
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
Nittya Ananda
Nittya Ananda 2023년 2월 24일
This is my interface, nothing is showing up in the output.
Walter Roberson
Walter Roberson 2023년 2월 24일
put a breakpoint at the line
L = func + lambda*lhs(cons);
and execute. When it gets there show us func and cons

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

답변 (1개)

Sarthak
Sarthak 2023년 3월 7일
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:

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by