"Error Inconsistent Assumptions" only when nesting symbolic functions.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
sanidhyak
am 7 Apr. 2025
Bearbeitet: Torsten
am 7 Apr. 2025
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 Kommentare
Siehe auch
Kategorien
Mehr zu Number Theory 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!