"Error Inconsistent Assumptions" only when nesting symbolic functions.
조회 수: 5 (최근 30일)
이전 댓글 표시
I do not understand why nesting one symbolic function (nchoosek) in another (user defined symbolic function) causes an error upon evaluation.
Why does the following assignment and evaluation work without error, when the "equivalent" function evaluation causes an "inconsistent assumption error"?
syms f(x, n)
f(x, n) = symsum(nchoosek(n, k), k, x, n);
% Incorrect range!
x = 2;
n = 1;
% The inner function works fine, when assigning variables manually,
symsum(nchoosek(n, k), k, x, n)
% but evaluating f directly does not work?
f(x, n)
The output is:
ans =
0
Error using symengine
Inconsistent assumptions.
Error in sym/subs>mupadsubs (line 160)
G = mupadmex('symobj::fullsubs',F.s,X2,Y2);
Error in sym/subs (line 145)
G = mupadsubs(F,X,Y);
Error in symfun/feval>evalScalarFun (line 42)
y = subs(formula(Ffun), Fvars, inds);
Error in symfun/feval (line 28)
varargout{1} = evalScalarFun(F, Fvars, varargin);
Error in symfun/subsref (line 175)
B = feval(A, inds{:});
Error in testing (line 9)
f(x, n)
Thank you
댓글 수: 0
답변 (1개)
sanidhyak
2025년 4월 7일
편집: Torsten
2025년 4월 7일
I understand that you are encountering the “Inconsistent assumptions” error when evaluating a symbolic function that nests “symsum” and “nchoosek” functions in MATLAB.
The root cause here is that symbolic variables x and n are being redefined as numeric values after defining a symbolic function “f(x, n)”. This causes inconsistency when evaluating the function, as MATLAB expects symbolic inputs for “symfun” functions.
To resolve this issue, please avoid overwriting symbolic variables directly. Instead, use “subs()” to evaluate your symbolic function with numeric values.
Kindly refer to the corrected code below:
syms x n k
f(x, n) = symsum(nchoosek(n, k), k, x, n); % Define symbolic function
% Evaluate using subs instead of assigning numeric values directly
result = subs(f(x, n), [x, n], [2, 1]);
disp(result);
The “subs()” function substitutes the numeric values safely into the symbolic function without conflicting assumptions. This method ensures proper evaluation and avoids the “Inconsistent assumptions” error.
For more information, you can refer to MATLAB’s documentation on symbolic functions:
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!