Unrecognized function or variable 'datachk'?
Show older comments
Soryy for the long Description. I have prepared a target function for optimization and am using it to build contours for now. Here is a function (a shorten version) to pass parameters to the target function:
function y = OptimizeFilter(A0, f, x0)
A0Val = vpa(A0);
fVal = vpa(f);
xC1 = linspace(0.1, 1.9);
yR1 = linspace(0.1, 1.9);
[XC1, YR1] = meshgrid(xC1, yR1);
fun=@(xx,yy) Target([xx,1,yy,1]);
Z=arrayfun(fun, XC1, YR1,'uniformoutput',false); % 2 last params I put in w/o much understanding on MATLAB's hint
contour(XC1, YR1, Z);
function y = Target(x)
y = 0;
for i = 1:length(fVal)
aCurrent = AmplAndDers(x0(1), x0(2), x0(3), x0(4), fVal(i), x(1), x(2), x(3), x(4));
dev = aCurrent - A0Val(i);
y = y + dev^2;
end
end
end
-----------------------
AmplAndDers() was generated by MATLAB out for objective function and its derivatives (1st and 2nd). It starts with (94 lines long):
function Ampl = AmplAndDers(C1_0,C2_0,R1_0,R2_0,w,x1,x2,x3,x4)
t2 = C1_0.^2;
t3 = C2_0.^2;
t4 = R1_0.^2;
t5 = R2_0.^2;
t6 = w.^2;
t8 = x1.^2;
t9 = x2.^2;
t10 = x3.^2;
t11 = x4.^2;
t12 = C2_0.*R1_0.*x3;
...
It behaves reasonably if I call from Command Window:
OptimizeFilter([1.12511646 3.8376244], [2089.296131 7585.77575], [0.1e-6 1.5e-9 16000 11000]);
but not when I call:
OptimizeFilter(A_Init, f, [0.1e-6 1.5e-9 16000 11000]);
Instead of prompt response in first case, it took 11 mins before it failed:
Unrecognized function or variable 'datachk'.
Error in contour (line 46)
[pvpairs, ~, ~, errmsg, warnmsg] = matlab.graphics.chart.internal.contourobjHelper('parseargs', false,
args{:});
Error in OptimizeFilter (line 28)
contour(XC1, YR1, Z);
I have a suspicion that the problem might be some remnants of symbolic business persisting in AmplAndDers() because terminating the run I would see some references to symbolic scope like:
In ./ (line 366)
X = privBinaryOp(A, B, 'symobj::zipWithImplicitExpansion', 'symobj::divide');
In AmplAndDers (line 53)
Ampl = 1.0./sqrt(t46);
In OptimizeFilter/Target (line 58)
aCurrent = AmplAndDers(x0(1), x0(2), x0(3), x0(4), fVal(i), x(1), x(2), x(3), x(4));
In OptimizeFilter>@(xx,yy)Target([xx,1,yy,1]) (line 21)
fun=@(xx,yy) Target([xx,1,yy,1]);
In OptimizeFilter (line 24)
Z=arrayfun(fun, XC1, YR1,'uniformoutput',false);
Admittedly C1_0, C2_0, ... and x are syms in Workspace, but I do pass numeric values to AmplAndDers(). Is that a problem?
3 Comments
Adam Danz
on 18 Aug 2021
Please provide information about XC1, YR1, Z including their class and size.
Valeri Aronov
on 19 Aug 2021
Edited: Valeri Aronov
on 19 Aug 2021
Adam Danz
on 19 Aug 2021
I see. Walter Roberson addressed this below. Matlab's error message is certainly not helpful in understanding that the inputs are unexpected.
Accepted Answer
More Answers (0)
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!