Power Series with coefficients as optimization parameters inside the nlcon
2 次查看(过去 30 天)
显示 更早的评论
Hi
I am solving an optimization problem. It is about finding the coefficients of a polynomial series so that a cost function is minimized. The series looks like this
normally to make such series one may use this method to create the symbolic sum. (N is known and x is a vector). We introduce n=2:N and Alpha as vectors to do so.
syms x
series=sum(Alpha(1:end).*(1-x).^n(1:end))
The above command creates the symbolic sum that we need when Alpha vector is known. After having the function also meshgrid x data can be inserted into the function for evaluation. However, I want to use this series in the nonlinear condition or in cost function of a fmincon or ga algorithm to minimize a cost function finally. This series needs to be calculated in both of my optimization functions. In the process, the Alpha is the optimization variable and hence the series should be created or called somehow inside the optimization function. I want to somehow define a function in the main mfile as a global or something and then use it inside my two optimization function. for instance, this is the cost function I tried:
function out=fun(alpha) % optimization targets are alphas
global xx yy N x %xx and yy are some meshgrid or vector points that later put into the series
temp=matlabFunction(sum(alpha(1:end).*(1-x).^N(1:end)));
Delx=temp(xx); %this function should be able to also get meshgrid of x points
the above method works but is so slow. since on every iteration, it creates the series. how can I remedy this problem in a time efficient manner? Thanks in advance.
0 个评论
回答(1 个)
Torsten
2018-10-15
You want to fit a polynomial to a number of (x,y)-data ? Why not just using "polyfit" ?
Or polyfitn if constant and linear term are missing:
https://de.mathworks.com/matlabcentral/fileexchange/34765-polyfitn
?
Best wishes
Torsten.
2 个评论
Torsten
2018-10-16
Try
function out = fun(alpha)
alpha = [fliplr(alpha) 0 0];
Delx = polyval(alpha,xx)
Best wishes
Torsten.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!