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!