Power Series with coefficients as optimization parameters inside the nlcon

2 Ansichten (letzte 30 Tage)
hossein
hossein am 12 Okt. 2018
Kommentiert: Torsten am 16 Okt. 2018
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.

Antworten (1)

Torsten
Torsten am 15 Okt. 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 Kommentare
hossein
hossein am 15 Okt. 2018
Bearbeitet: hossein am 15 Okt. 2018
Thanks for your reply and your time. Actually, the problem is not that simple. I do not have the f(x,y) points. only (x,y) are known which are on a circular or rectangular grid. I have a general formula for f(x,y) function which has a certain form of polynomial shape. The coefficients are the only unknowns. The aim is to find those coefficients such that: the f(x,y) remains between >1 and <3(for instance). Also, this coefficients should add up to 1 to satisfy another property that the problem requires. This is why I need to do an optimization using Fmincon or ga.
Torsten
Torsten am 16 Okt. 2018
Try
function out = fun(alpha)
alpha = [fliplr(alpha) 0 0];
Delx = polyval(alpha,xx)
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by