Power Series with coefficients as optimization parameters inside the nlcon
조회 수: 3 (최근 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에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!