Re: [問題]請問哪裡有錯(函數用法)已回收

看板MATLAB作者 (Without Charge)時間16年前 (2009/02/12 08:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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 的範例目錄. 也許你的問題只是目錄的問題 --  ╔╯═╗  ╦╦╦ ╬╬╯ ╰╦ ╬ ╬╬╗ ╦╰╬═  ╠╬═ ══   ╔══╗ ╔╬╬╗ ╬ ╩ ║ ╬>║< ╬═ ╔╗╔╗ ∕╚﹨﹨ ╠═ ╠═ ║ ╔╬╗ ╚╯ ╩ ╝  ╩═ ╚╝║╯   ╠═╗ ╚═╗╚══╝ ╠╬║    ╬╬║ ═╬ ╬ 國家研究院AcademyEarthAstroEcophilia環境板 ╯ 。 ╯ ╩╯ m3m3ρ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 142.244.32.84 ※ 編輯: WC 來自: 142.244.32.84 (02/12 08:15)
文章代碼(AID): #19asVhbw (MATLAB)
文章代碼(AID): #19asVhbw (MATLAB)