Re: [問題]請問哪裡有錯(函數用法)已回收
※ 引述《qwer098 (^^)》之銘言:
: 這是help理的範例
: 我複製照著做
: function [c, ceq] = confun(x)
: % Nonlinear inequality constraints
: c = [1.5 + x(1)*x(2) - x(1) - x(2);
: -x(1)*x(2) - 10];
: % Nonlinear equality constraints
: ceq = [];
: 以上存在m.file裡
: x0 = [-1,1]; % Make a starting guess at the solution
: options = optimset('LargeScale','off');
: [x, fval] = ...
: fmincon(@objfun,x0,[],[],[],[],[],[],@confun,options)
: 然後去跑...但出現Error using ==> fmincon
: FMINCON cannot continue because user supplied objective function failed with the following error:
: Error: File: C:\Program Files\MATLAB71\work\objfun.m Line: 13 Column: 1
: Function definitions are not permitted at the prompt or in scripts.
: 我該如何修改?
我也照著作
跑出來的是
Optimization terminated: first-order optimality measure less
than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
2
x =
-9.547405033629550 1.047405033629039
fval =
0.023550379447862
也不知道對不對, 不過我什麼都沒改, 你說要存 .m 檔, 我也存了
這樣我也不知從何幫起呢
==
剛剛跑去查說明檔, 你還漏了一個 objfun.m 沒建
function f = objfun(x)
f = exp(x(1))*(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1);
那為什麼我沒有 objfun.m 一樣可以得到答案呢? 因為 matlab 有指定路徑到 optimization
toolbox 的範例目錄.
也許你的問題只是目錄的問題
--
。 ╔╯═╗ ╦╦╦ ╬╬╯ ╰╦
╬ ╬╬╗ ╦╰╬═ ╠╬═ ══ ╔══╗ ╔╬╬╗ ╬
╩ ║ ╬>║< * ╬═ ╔╗╔╗* ∕╚﹨﹨ ╠═ ╠═ ║ ╔╬╗
╚╯ ╩ ╝ ═╩═ ╚╝║╯ ╠═╗ ╚═╗╚══╝ ╠╬║
╳ ╬╬║ ═╬ ╬
國家研究院》Academy》EarthAstro》Ecophilia環境板 ╯ 。 ╯ ╩╯ m3m3ρ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 142.244.32.84
※ 編輯: WC 來自: 142.244.32.84 (02/12 08:15)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章