| 4 | 1/1 | 返回列表 |
| 查看: 1117 | 回復(fù): 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; 結(jié)果 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 |

金蟲 (小有名氣)

榮譽版主 (著名寫手)
彩色掛圖
![]() |
專家經(jīng)驗: +2 |
|
stop只能是false或true,然后通過stop來判斷是否跳出。你不用它就設(shè)為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'); |

| 4 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿華中科技大學(xué),080502,354分求調(diào)劑 +4 | 守候夕陽CF 2026-03-18 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 一志愿吉林大學(xué)材料學(xué)碩321求調(diào)劑 +4 | Ymlll 2026-03-18 | 6/300 |
|
|
[考研] 274求調(diào)劑 +5 | S.H1 2026-03-18 | 5/250 |
|
|
[教師之家] 焦慮 +8 | 水冰月月野兔 2026-03-13 | 12/600 |
|
|
[考研] 化學(xué)工程321分求調(diào)劑 +15 | 大米飯! 2026-03-15 | 18/900 |
|
|
[考研] 0817 化學(xué)工程 299分求調(diào)劑 有科研經(jīng)歷 有二區(qū)文章 +7 | rare12345 2026-03-18 | 7/350 |
|
|
[考研] 085601材料工程專碩求調(diào)劑 +6 | 慕寒mio 2026-03-16 | 6/300 |
|
|
[考研] 0703化學(xué)調(diào)劑 ,六級已過,有科研經(jīng)歷 +10 | 曦熙兮 2026-03-15 | 10/500 |
|
|
[考研] 301求調(diào)劑 +9 | yy要上岸呀 2026-03-17 | 9/450 |
|
|
[考研] 293求調(diào)劑 +11 | zjl的號 2026-03-16 | 16/800 |
|
|
[考博] 26博士申請 +3 | 1042136743 2026-03-17 | 3/150 |
|
|
[考研] 考研求調(diào)劑 +3 | 橘頌. 2026-03-17 | 4/200 |
|
|
[考研] 中科院材料273求調(diào)劑 +4 | yzydy 2026-03-15 | 4/200 |
|
|
[考研] 中科大材料專碩319求調(diào)劑 +3 | 孟鑫材料 2026-03-13 | 3/150 |
|
|
[考研] 招收0805(材料)調(diào)劑 +3 | 18595523086 2026-03-13 | 3/150 |
|
|
[考研] 304求調(diào)劑 +6 | Mochaaaa 2026-03-12 | 7/350 |
|
|
[考研] 材料工程調(diào)劑 +9 | 咪咪空空 2026-03-12 | 9/450 |
|
|
[考研] [0860]321分求調(diào)劑,ab區(qū)皆可 +4 | 寶貴熱 2026-03-13 | 4/200 |
|
|
[考研] 085600材料與化工 309分請求調(diào)劑 +7 | dtdxzxx 2026-03-12 | 8/400 |
|
|
[考博] 26讀博 +4 | Rui135246 2026-03-12 | 10/500 |
|