# Fit: ExperimentalNumericalFunction error when fitting a black-box function

Bug appearing in at least 12.0.0 and 12.3.1

I'm trying some multidimensional Chebyshev fits. First, define a wrapper to prevent premature symbolic evaluation (I don't want a power series result):

cheb[n_Integer, x_?NumericQ] := ChebyshevT[n, x]


Function to construct list of basis functions for Fit:

chebasis[vars_List, n_Integer] :=
Flatten@Outer[Times, Sequence @@
Transpose@Table[cheb[i, #] & /@ vars, {i, 0, n}]]


Now, make some test data:

tdata = N[Flatten[Table[{x, y, x y}, {x, -1, 1}, {y, -1, 1}], 1]];


Attempt a fit:

Fit[tdata, chebasis[{x, y}, 1], {x, y}] // Chop


Emits an error message:

ExperimentalNumericalFunction::dimsl: {y} given in {x,y} should be a list of dimensions for a particular argument.


It does, however yield a sensible result:

1. cheb[1, x] cheb[1, y]


So, what's going on here? Is it harmless? Can I avoid it?

• For whatever it's worth the "equivalent" fit with NonlinearModelFit (NonlinearModelFit[tdata, {a1, a2, a3, a4} . chebasis[{x, y}, 1], {a1, a2, a3, a4}, {x, y}] // Chop) gives the same error message and fit.
– JimB
Oct 21 '21 at 15:46
• Please write an INFORMATIVE (not vague, cutesy, and confusing) title. Oct 21 '21 at 19:44
• @DavidG.Stork If you don't have something constructive to offer, please don't comment. Oct 21 '21 at 20:25
• @John Doty: This IS a constructive comment. It points out a weakness. Innumerable other comments are the same, saying a question is (for instance), too vague, or unclear, or needs more work, or should be typeset. I expect you complain about such thousands of comments too, right? Oh... what is "the beast", specifically? And "annoys"? Oct 21 '21 at 22:05
• I have to say I agree with @DavidG.Stork. The purpose of a good title is so that future users searching in stack exchange for a similar question should be able to find this one and therefore not write a duplicate. It also serves the purpose of giving potential answerers a quick idea of what the question is about, which allows them to waste less time clicking through (or wasting your time by not clicking through due to the title not having enough information about the question). Oct 22 '21 at 15:31

It looks like a bug. Fit tries to create a numerical function with

ExperimentalCreateNumericalFunction[{{x, y}},
{cheb[0, x] cheb[0, y], cheb[0, x] cheb[1, y], cheb[0, y] cheb[1, x],
cheb[1, x] cheb[1, y]}, {4}]
(* ExperimentalNumericalFunction::dimsl error *)


But it should call it without the extra {} in the first argument:

ExperimentalCreateNumericalFunction[{x, y},
{cheb[0, x] cheb[0, y], cheb[0, x] cheb[1, y], cheb[0, y] cheb[1, x],
cheb[1, x] cheb[1, y]}, {4}]


The failure of CreateNumericalFunction` just means it falls back on some other method of evaluation.