シンボリック式を目的関数として最適化することはできますか?
15 views (last 30 days)
Show older comments
MathWorks Support Team
on 25 Oct 2013
Answered: MathWorks Support Team
on 25 Oct 2013
下記のようなシンボリック式を最適化しようとしています。具体的な方法を教えてください。
syms x1 x2
y = [2*x1-x2-exp(-x1);-x1+2*x2-exp(-x2)];
Accepted Answer
MathWorks Support Team
on 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))];
0 Comments
More Answers (0)
See Also
Categories
Find more on コード生成 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!