I have a simple performance question on using polyval function with Matlab.
Currently, I have a vector of x that can be quite long (>1000 scalars). I want to apply a different polynomial form to each of the x.
The polynomial forms are stored in a 2d array and applied in a loop like the code below. The code is relatively fast as polyval is optimized but the loop can be lengthy and performance is paramount as it is an objective function that can be computed thousands of times in a process.
Any idea on how to improve the performance?
Thanks
% ---------- Objective Function ------------------
function [obj] = obj(x, poly_objective)
polyvalue = zeros(length(x),1);
for index = 1: length(x)
polyvalue (index) = polyval(poly_objective(index,:), x(index));
end
obj= -sum(polyvalue );
end
% -------------------------------------------------