i have a equation, y = 0.009(1 + x)^0.278
i want to solve it through genetic algorithm
the output says to put atleast 2 arguments
how to operate ga on single variable, do tell

2 Comments

Hi Shyam,
Does the parameter description in the documentation help. You can take a look at the documentation here
nothing as such mentioned in the documentation

Sign in to comment.

 Accepted Answer

You do not define any range for x, so it could be less than -1, leading to a negative value raised to a fraction. It is not clear what the "optimal" value for a complex function is.
y = @(x) norm(0.009*(1 + x).^0.278)
y = function_handle with value:
@(x)norm(0.009*(1+x).^0.278)
nvars = 1;
[bestx, fval] = ga(y, nvars)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
bestx = -0.9942
fval = 0.0021
%cross-check
syms X real
Y = y(X)
Y = 
dY = diff(Y,X)
dY = 
fplot([Y, dY], [-2 2])
bestX = solve(dY,X)
bestX = Empty sym: 0-by-1
vpa(bestX)
ans = Empty sym: 0-by-1
No best value in calculus because it has a discontinuity in the derivative.

4 Comments

please tell me how to put range of x for function to be solved by ga
i have x in the row vector form (1*84)
You earlier indicated that x is a single variable, but now you are talking about a 1 x 84 variable. I do not know how the 1 x 84 is intended to fit into this problem?
y = @(x) 0.009*(1 + x).^0.278
y = function_handle with value:
@(x)0.009*(1+x).^0.278
lb = -1; ub = 10;
A = []; b = []; Aeq = []; beq = [];
nvars = 1;
[bestx, fval] = ga(y, nvars, A, b, Aeq, beq, lb, ub)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
bestx = -1
fval = 0
Thank you for your time,
my intentions are to get minimum value of function through ga
i need to check the function at some particular values of x (84 values i have) , out of these 84 values , if ga could tell me where function will be minimum and x value where it's minimum,
so isn't there any way where i can define the x values where ga should check and give me minimum value accordingly,
upper and lower bounds wouldnt help
If you have a vector of specific values, and there are no model parameters to change, then you would just evaluate the function at the 84 different values and use min()
You would only use ga() if there is something that has to be changed. For example if you had
y = @(x,p) 0.009*(1 + x).^(p-x)
y = function_handle with value:
@(x,p)0.009*(1+x).^(p-x)
then it would make sense to define something like
nvars = 1;
lb = -1; ub = 10;
A = []; b = []; Aeq = []; beq = [];
x = sort(rand(1,15) * (ub-lb) + lb)
x = 1×15
-0.9596 -0.8781 -0.2031 0.0707 1.2581 3.4550 4.2471 4.3598 4.4943 5.6380 7.7537 7.7766 8.2198 9.6891 9.6978
pvals = arrayfun(@(X) ga(@(p) y(X,p), nvars, A, b, Aeq, beq, lb, ub), x).'
Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance. Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
pvals = 15×1
10.0000 10.0000 10.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000 -1.0000
In the case of this particular function, the outcome can be predicted as being the ub if x is negative, and the lb if x is positive, but you could imagine other objectives in which the value of x played a more important role.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!