combining strings by using loops
1 次查看(过去 30 天)
显示 更早的评论
I want to use genetic algorithm (from global optimization toolbox) to optimize a function. My function is f(x1,x2,x3)=a.*x1^2+b.*x2^2+c./x3
I have a database (1000*4) in which 1000 is the number of observations and 4 is the number of variables+Output; i.e, x1, x2, x3 and a measured (I got it by doing experiments in my lab) value which is the result of x1,x2 and x3. I will call the forth column the Outputs
I want to minimize F (by finding the best-fit a,b and c) which is the difference between the measured values and predicted values by f function. To minimize the F function I must write F as follow:
F=((a.*x1(1,1)^2+b.*x2(1,2)^2+c./x3(1,3))-Outputs(1,1)+...
a.*x1(2,1)^2+b.*x2(2,2)^2+c./x3(2,3))-Outputs(2,1)+...
.
.
.
a.*x1(1000,1)^2+b.*x2(1000,2)^2+c./x3(1000,3))-Outputs(1000,1))
0 个评论
回答(2 个)
Walter Roberson
2012-11-9
F = sum( a .* x1(:,1).^2 + b.* x2(:,2).^2 + c ./ x3(:,3) - Outputs(:,1) );
Muruganandham Subramanian
2012-11-9
编辑:Muruganandham Subramanian
2012-11-9
N=1000;
F=0;
for i=1:N
if i==1
F(i)=F(i) +a.*x1(i,1)^2+b.*x2(i,2)^2+c./x3(i,3))-Outputs(i,1);
else
F(i)=F(i-1) +a.*x1(i,1)^2+b.*x2(i,2)^2+c./x3(i,3))-Outputs(i,1);
end
F1=sum(F);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!