シンボリック式を目的​関数として最適化する​ことはできますか?

8 vues (au cours des 30 derniers jours)
MathWorks Support Team
MathWorks Support Team le 25 Oct 2013
下記のようなシンボリック式を最適化しようとしています。具体的な方法を教えてください。
syms x1 x2
y = [2*x1-x2-exp(-x1);-x1+2*x2-exp(-x2)];

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 25 Oct 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))];

Plus de réponses (0)

Catégories

En savoir plus sur コード生成 dans Help Center et File Exchange

Produits


Version

R2011b

Community Treasure Hunt

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

Start Hunting!