combining strings by using loops
조회 수: 4 (최근 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!