シンボリック式を目的関数として最適化することはできますか?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 25 Okt. 2013
Beantwortet: MathWorks Support Team
am 25 Okt. 2013
下記のようなシンボリック式を最適化しようとしています。具体的な方法を教えてください。
syms x1 x2
y = [2*x1-x2-exp(-x1);-x1+2*x2-exp(-x2)];
Akzeptierte Antwort
MathWorks Support Team
am 25 Okt. 2013
matlabFunction 関数で、シンボリック式から目的関数を作成することができます。
x0 = [-5; -5];
options = optimset('Display','iter');
syms x1 x2
y = [2*x1-x2-exp(-x1);-x1+2*x2-exp(-x2)]
myfun2 =matlabFunction(y);
fun = @(x) myfun2(x(1),x(2)); % 目的関数の作成
[x3,fval2] = fsolve(fun,x0,options)
上記例は以下と同様の処理となります。
function samp_fsolve
x0 = [-5; -5];
options = optimset('Display','iter');
[x1,fval1] = fsolve(@myfun,x0,options)
function F = myfun(x)
F = [2*x(1) - x(2) - exp(-x(1));
-x(1) + 2*x(2) - exp(-x(2))];
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu コード生成 finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!