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 件のコメント

Githin George
Githin George 2022 年 7 月 26 日
Hi Shyam,
Does the parameter description in the documentation help. You can take a look at the documentation here
Shyam pratap singh rathore
Shyam pratap singh rathore 2022 年 7 月 26 日
nothing as such mentioned in the documentation

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2022 年 7 月 26 日

0 投票

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 件のコメント

Shyam pratap singh rathore
Shyam pratap singh rathore 2022 年 7 月 26 日
編集済み: Shyam pratap singh rathore 2022 年 7 月 26 日
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)
Walter Roberson
Walter Roberson 2022 年 7 月 26 日
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
Shyam pratap singh rathore
Shyam pratap singh rathore 2022 年 7 月 27 日
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
Walter Roberson
Walter Roberson 2022 年 7 月 27 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Systems of Nonlinear Equations についてさらに検索

製品

リリース

R2022a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by