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

15 次查看(过去 30 天)
MathWorks Support Team
下記のようなシンボリック式を最適化しようとしています。具体的な方法を教えてください。
syms x1 x2
y = [2*x1-x2-exp(-x1);-x1+2*x2-exp(-x2)];

采纳的回答

MathWorks Support Team
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 个)

类别

Help CenterFile Exchange 中查找有关 コード生成 的更多信息

产品


版本

R2011b

Community Treasure Hunt

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

Start Hunting!