can someone help to write this the rosenbrock function for PSO and DE

14 ビュー (過去 30 日間)
Cesario Anderson Mouzinho 2024 年 4 月 17 日

function f = rosenbrock_function(x)
d = length(x);
f = 0;
for i = 1:(d-1)
f = f + 100*(x(i+1) - x(i)^2)^2 + (1 - x(i))^2;
2 件のコメントなしを表示なしを非表示
Sam Chak 2024 年 4 月 17 日
Could you please, with the least efforts, provide the basic Rosenbrock function in MATLAB code? You can click the indentation icon to insert the code. This will enable other users to review and provide guidance on which function to use for summing up the terms.
function f = rosenbrock(x)
f = ...;
end
Cesario Anderson Mouzinho 2024 年 4 月 17 日
function f = rosenbrock_function(x)
d = length(x);
f = 0;
for i = 1:(d-1)
f = f + 100*(x(i+1) - x(i)^2)^2 + (1 - x(i))^2;

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

回答 (1 件)

Aman 2024 年 4 月 22 日
Hi Cesario,
As per my understanding, you want to use the rosenbrock function as the fitness function in the particle swarm optimization (PSO) and differential evolution (DE) functions for evaluating their convergence and performance.
The way you have implemented it is correct, so while calculating the fitness of a particle, you just need to call this function and pass the position vector of the particle as a parameter.
You can refer to the below video, which also explains how to use this function in a number of ways:
I hope this helps!

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

カテゴリ

Help Center および File ExchangeParticle Swarm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by