Power Series with coefficients as optimization parameters inside the nlcon
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Torsten
on 15 Oct 2018
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 Comments
Torsten
on 16 Oct 2018
Try
function out = fun(alpha)
alpha = [fliplr(alpha) 0 0];
Delx = polyval(alpha,xx)
Best wishes
Torsten.
See Also
Categories
Find more on Get Started with Optimization Toolbox 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!