combining strings by using loops
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Walter Roberson
on 9 Nov 2012
F = sum( a .* x1(:,1).^2 + b.* x2(:,2).^2 + c ./ x3(:,3) - Outputs(:,1) );
Muruganandham Subramanian
on 9 Nov 2012
Edited: Muruganandham Subramanian
on 9 Nov 2012
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);
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!