Optimize a function with a sum of series

10 ビュー (過去 30 日間)
Dmytro Stovolos
Dmytro Stovolos 2021 年 12 月 12 日
コメント済み: Dmytro Stovolos 2021 年 12 月 13 日
Hello. Basically, I need to optimize the following function
Function
The minimum value for 'n' is 2. Imagine we have n = 25. I have a sum of series so I tried the following:
syms i n
x0=[2:25];
i=[1:25];
f1= @(x)(x(1)+7)^8
f2 = @(x)((0.01*x(i)-i)^2)/i
All looks good until I try to sum both parts
fun = f1+symsum(f2,i,2,25);
Check for missing argument or incorrect argument data type in call to function 'symsum'.
If the previous step was correct, I would call "fminunc(fun,x0);" to optimize the function.
Could you explain why I get this error? 'i' should be a symbolic variable because of being created by syms call. Set of 'x' is defined. I must have missed something but can't find out what.
  2 件のコメント
Paul
Paul 2021 年 12 月 12 日
For n = 25, it looks like y is function of x1 - x25, i.e., . Is that correct?
What is ? That term doesn't show up in the equation for y.
Dmytro Stovolos
Dmytro Stovolos 2021 年 12 月 13 日
Hello Paul, is a starting value of the corresponding x value. For example, (1) = 2; (2) = 3. Yes, for n = 25 the function represents summation from to .

サインインしてコメントする。

採用された回答

Abolfazl Chaman Motlagh
Abolfazl Chaman Motlagh 2021 年 12 月 12 日
編集済み: Abolfazl Chaman Motlagh 2021 年 12 月 12 日
Hi , you don't need necessarily symboilic functionality for this problem. here is a simple solution. (you can run it in single .m file)
clear;
n = 25;
x0 = 1:n;
optimoptions = optimoptions(@fminunc,'Algorithm','quasi-newton',...
'OptimalityTolerance',1e-10,'MaxFunctionEvaluations',1e7,...
,'PlotFcn','optimplotx','Display','iter'); % this line is just for illustration of convergence process
[X,fval,exitflag,output] = fminunc(@(x)(Cost(x,n)),x0,optimoptions);
function y=Cost(x,n)
y = (x(1)+7)^8;
for i=2:n
y = y + (1/i)*((0.1*x(i)-i)^2);
end
end
you may ask why i use optimoptions so serious. in your problem the optimal solution is obvious because every single term is squared of a linear expression. so if x(1) became -7 and for i=2:n, x(i) = i/0.01. the function became 0. with this knowlegde i use more options to see the actual convergence of function. you can test that with no options, optimization stop at very high value point.
  1 件のコメント
Dmytro Stovolos
Dmytro Stovolos 2021 年 12 月 13 日
Hello. Thanks for the answer.
If I run with optimoptions I get "Local minimum possible." but if I run without it I get "Local minimum found."
Indeed, fval is high without optimoptions but with this variable the solution is not guaranteed. Please correct me if I am wrong.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by