How to solve a cubic equation using Genetic Algorithms?
6 ビュー (過去 30 日間)
古いコメントを表示
Hello there,
I want to write a code in matlab that finds a real solution for the equation x^3+x^2+x+7=0 , -5<x<5, using Genetic Algorithms.
How can I implement that with code?
0 件のコメント
採用された回答
その他の回答 (1 件)
Walter Roberson
2021 年 4 月 20 日
編集済み: Walter Roberson
2021 年 4 月 20 日
f = @(x) x.^4-2*x.^3+3*x.^2+x-4
target = 5;
residue = @(x) (f(x)-target).^2
[bestx, fval] = ga(residue, 1)
roots([1, -2, 3, 1, -4-target])
2 件のコメント
Walter Roberson
2021 年 4 月 20 日
One that computed the left hand side of that polynomial, with the target set to the constant that is the right hand side of the equation.
... you are obviously answering homework, so I deliberately showed you how to do it for a different polynomial, so that you would have to do at least minimal study of the technique instead of just copying what I posted.
参考
カテゴリ
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!