how to write matlab code for following equation

3 个评论

If you have the optimisation toolbox you can search in there for Genetic Algorithm functionality. If you don't you will either have to program the algorithm yourself or search in the Matlab File Exchange which is linked at the top of this web page.
what is GA? also when it's asking to minimize my mind goes to optimization , anyway i will post below some code so you can see if that's gonna help you in someway.
minor_lobe_range=10; %you can specify your parameter
n=15; %specify your n range limit
b=100; %specify your b parameter
for theta=1:minor_lobe_range
for k=1:n-1
fit1(theta)=abs(1+sum(a(k)*exp(-1i*(b*d(k)*cos(theta)+f(k)))));
end
end
Hi Manolis, thanks for reply, the codes were helpful but i want to know hoe can we use GA to optimize any function by taking any particular variable.
As in this example, it is written that "Apply GA to minimize fit1, taking 'd' as a parameter"
Please explain with a simple example or use this example..
Thanks

请先登录,再进行评论。

 采纳的回答

Example:
simple_fitness = @(x, d) 100 * (x(1).^2 - x(2)).^2 + d * (1 - x(1)).^2;
d = rand() * 100; %some value
ga(@(x) simple_fitness(x, d), .....)

3 个评论

Hi Walter,
Can you give another example
for ex. use this
y = a*x^2+5*x*b-c
and i want to apply GA to optimize this taking 'b' as a parameter
or you can take any other example..
fitness_fun = @(x,b) a*x.^2 + 5*b*x - c;
b = rand() * 100; %some value
ga(@(x) fitness_fun(x, b), ....)
However, that isn't what the diagram in the Question is asking about. What the diagram in the question is asking about would be equivalent to
Vector a, vector phi
fit1fun = @(d) abs(1 + sum(a .* exp(-1i * (beta * cos(theta) + phi))));
d_initial = randn(1,n-1)
best_d = ga(fit1fun, d_initial, .....);
That is, d is the (vector of) parameters whose value needs to be found as optimizing fit1.
Hi, Thanks for reply. Actually i am still facing problem in executing this question, I have coded as follows:
I made a filness function "fitfu2" as
function y = fitfu2(N)
%N = 12; % element numbers
j = sqrt(-1);
AF = zeros(1,360);
deg2rad=zeros(1,360);
for theta = 20:90
deg2rad(theta) = (theta*pi)/180;
for k = 1:N-1
for d = 0:0.5:0.5*k
for n=1:N-1
AF(theta) = AF(theta) + exp(j*n*2*pi*d*(cos(deg2rad(theta))));
end
AF(theta)=1+AF(theta);
end
end
end
y = abs(AF(theta));
and then I used following codes to use multiobjective genetic optimization toolbox
N=12; % Number of elements
FitnessFunction = @(d) fitfu2(N);
NumberOfVariables = 19;
options = gaoptimset('PopulationSize',20);
[x,f] = gamultiobj(FitnessFunction,NumberOfVariables,[],[],[],[],2,10,options);
This is executing but i am confused about how to get desired output and values
If there is any Error or wrong coding ,Please Rectify and send me back the codes.
It will be very kind of you....

请先登录,再进行评论。

更多回答(0 个)

类别

Community Treasure Hunt

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

Start Hunting!

Translated by