combining strings by using loops

조회 수: 4 (최근 30일)
Ronaldo
Ronaldo 2012년 11월 9일
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))

답변 (2개)

Walter Roberson
Walter Roberson 2012년 11월 9일
F = sum( a .* x1(:,1).^2 + b.* x2(:,2).^2 + c ./ x3(:,3) - Outputs(:,1) );
  댓글 수: 1
Ronaldo
Ronaldo 2012년 11월 9일
I tried your answer. Unfortunately, it is not working. The genetic algorithm code cannot optimize the function that you proposed. I need a procedure that I can get the following result from this input:
Input:
f(x1,x2,x3)=a.*x1^2+b.*x2^2+c./x3
Result:
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))

댓글을 달려면 로그인하십시오.


Muruganandham Subramanian
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);
  댓글 수: 1
Ronaldo
Ronaldo 2012년 11월 9일
No, this is not the answer. Let me make the question more clear. I do not need the summation value of function F. I need a procedure to make the following big string (not its value). 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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by