| 5 | 1/1 | 返回列表 |
| 查看: 1133 | 回復: 3 | |||||
| 當前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | |||||
smileheaven金蟲 (小有名氣)
|
[求助]
MATLAB非線性優(yōu)化擬合怎么改才正確
|
||||
|
想對函數(shù)z求一下x和Fval的最優(yōu)解,其中x1的取值范圍在0.3到1.8,x2的取值范圍在1到2,均為閉區(qū)間。以下是自己編的程序 function [x fval history] = myproblem1(x0) history = [] options = optimset('OutputFcn', @myoutput) [x fval] = fminsearch(@objfun, x0,options) function stop = myoutput(x,optimvalues,state) stop=[] if state == 'iter' history = [history; x] end end function z = objfun(x) z = 124.5993*x(1)^2-371.4544*x(1)+712.1124-1359.4398*x(2)^2+4028.7765*x(2)-2244.7098 end end 但是返回的錯誤卻是 ??? In an assignment A( = B, the number of elements in A and Bmust be the same. Error in ==> callAllOptimOutputFcns at 12 stop(i) = feval(OutputFcn{i},xOutputfcn,optimValues,state,varargin{:}); Error in ==> fminsearch>callOutputAndPlotFcns at 478 stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:}) || stop; Error in ==> fminsearch at 213 [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'init',itercount, ... Error in ==> myproblem1 at 4 [x fval history] = fminsearch(@objfun, x0,options) 請各位蟲哥蟲姐幫忙看看,謝謝啦 |

榮譽版主 (著名寫手)
彩色掛圖
![]() |
專家經(jīng)驗: +2 |
|
stop只能是false或true,然后通過stop來判斷是否跳出。你不用它就設為false,而不是[];再用state判斷 Stop Flag The output argument stop is a flag that is true or false. The flag tells the optimization function whether the optimization should quit or continue. The following examples show typical ways to use the stop flag. Stopping an Optimization Based on Data in optimValues The output function can stop an optimization at any iteration based on the current data in optimValues. For example, the following code sets stop to true if the objective function value is less than 5: function stop = myoutput(x, optimValues, state) stop = false; % Check if objective function is less than 5. if optimValues.fval < 5 stop = true; end Stopping an Optimization Based on GUI Input If you design a GUI to perform optimizations, you can make the output function stop an optimization when a user clicks a Stop button on the GUI. The following code shows how to do this, assuming that the Stop button callback stores the value true in the optimstop field of a handles structure called hObject stored in appdata. function stop = myoutput(x, optimValues, state) stop = false; % Check if user has requested to stop the optimization. stop = getappdata(hObject,'optimstop'); |

榮譽版主 (著名寫手)
彩色掛圖
![]() |
專家經(jīng)驗: +2 |
|
stop=false; 結果 state = done Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: -31981372058113011000000000000000000000000000000000000000000000000000000000000000000000000000.000000 x = 1.0e+044 * 0.1905 1.5349 fval = -3.1981e+091 result = 1.0e+044 * 0.1905 1.5349 |

金蟲 (小有名氣)

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 284求調(diào)劑 +5 | 小熊~~ 2026-03-31 | 5/250 |
|
|---|---|---|---|---|
|
[考研] 吉大生物學326分求調(diào)劑 +3 | sunnyupup 2026-03-31 | 3/150 |
|
|
[考研] 08工科求調(diào)劑286 +5 | tgs_001 2026-03-28 | 5/250 |
|
|
[考研] 一志愿食品科學與工程083200求調(diào)劑 +4 | XQTJZ 2026-03-30 | 4/200 |
|
|
[考研] 英一數(shù)一408,總分284,二戰(zhàn)真誠求調(diào)劑 +3 | 12.27 2026-03-30 | 5/250 |
|
|
[有機交流]
10+3
|
kaobao456 2026-03-29 | 4/200 |
|
|
[考研] 抱歉 +4 | 田洪有 2026-03-30 | 4/200 |
|
|
[考研] 生物學 296 求調(diào)劑 +5 | 朵朵- 2026-03-26 | 7/350 |
|
|
[考研] 293求調(diào)劑 +3 | 末未mm 2026-03-30 | 5/250 |
|
|
[考研] 283求調(diào)劑(080500) +14 | A child 2026-03-27 | 14/700 |
|
|
[考研] 085600,專業(yè)課化工原理,321分求調(diào)劑 +5 | 大饞小子 2026-03-28 | 5/250 |
|
|
[考研] 085701環(huán)境工程,267求調(diào)劑 +16 | minht 2026-03-26 | 16/800 |
|
|
[考研] 292求調(diào)劑 +14 | 鵝鵝鵝額額額額?/a> 2026-03-25 | 15/750 |
|
|
[考研] 一志愿上海理工能源動力(085800)310分求調(diào)劑 +3 | zhangmingc 2026-03-27 | 4/200 |
|
|
[考研] 08開頭275求調(diào)劑 +4 | 拉誰不重要 2026-03-26 | 4/200 |
|
|
[考研] 材料求調(diào)劑 +5 | .m.. 2026-03-25 | 5/250 |
|
|
[考研] 085601求調(diào)劑總分293英一數(shù)二 +4 | 鋼鐵大炮 2026-03-24 | 4/200 |
|
|
[考研] 290分調(diào)劑求助 +3 | 吉祥止止陳 2026-03-25 | 3/150 |
|
|
[考研] 347求調(diào)劑 +4 | L when 2026-03-25 | 4/200 |
|
|
[考研] 277分求調(diào)劑,跨調(diào)材料 +3 | 考研調(diào)劑lxh 2026-03-24 | 3/150 |
|