| 4 | 1/1 | 返回列表 |
| 查看: 1118 | 回復(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) 請各位蟲哥蟲姐幫忙看看,謝謝啦 |

榮譽(yù)版主 (著名寫手)
彩色掛圖
![]() |
專家經(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 |

金蟲 (小有名氣)

榮譽(yù)版主 (著名寫手)
彩色掛圖
![]() |
專家經(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ā)表 | |
|---|---|---|---|---|
|
[考研] 281求調(diào)劑(0805) +6 | 煙汐憶海 2026-03-16 | 16/800 |
|
|---|---|---|---|---|
|
[考研] 354求調(diào)劑 +4 | Tyoumou 2026-03-18 | 7/350 |
|
|
[考研] 能源材料化學(xué)課題組招收碩士研究生8-10名 +4 | 脫穎而出 2026-03-16 | 10/500 |
|
|
[考研] 331求調(diào)劑(0703有機(jī)化學(xué) +7 | ZY-05 2026-03-13 | 8/400 |
|
|
[考研] 334求調(diào)劑 +3 | 志存高遠(yuǎn)意在機(jī)?/a> 2026-03-16 | 3/150 |
|
|
[考研] 277調(diào)劑 +5 | 自由煎餅果子 2026-03-16 | 6/300 |
|
|
[考研] 085600材料與化工求調(diào)劑 +5 | 緒幸與子 2026-03-17 | 5/250 |
|
|
[考研] 有沒有道鐵/土木的想調(diào)劑南林,給自己招師弟中~ +3 | TqlXswl 2026-03-16 | 7/350 |
|
|
[論文投稿] 有沒有大佬發(fā)小論文能帶我個二作 +3 | 增銳漏人 2026-03-17 | 4/200 |
|
|
[考研] 一志愿,福州大學(xué)材料專碩339分求調(diào)劑 +3 | 木子momo青爭 2026-03-15 | 3/150 |
|
|
[考研] 321求調(diào)劑 +5 | 大米飯! 2026-03-15 | 5/250 |
|
|
[考研] 327求調(diào)劑 +6 | 拾光任染 2026-03-15 | 11/550 |
|
|
[考博] 東華理工大學(xué)化材專業(yè)26屆碩士博士申請 +6 | zlingli 2026-03-13 | 6/300 |
|
|
[考研] 中科大材料與化工319求調(diào)劑 +3 | 孟鑫材料 2026-03-14 | 3/150 |
|
|
[考研] [0860]321分求調(diào)劑,ab區(qū)皆可 +4 | 寶貴熱 2026-03-13 | 4/200 |
|
|
[考研] 一志愿211化學(xué)學(xué)碩310分求調(diào)劑 +8 | 努力奮斗112 2026-03-12 | 9/450 |
|
|
[考研] 土木第一志愿276求調(diào)劑,科研和技能十分豐富,求新興方向的導(dǎo)師收留 +3 | 土木小天才 2026-03-12 | 3/150 |
|
|
[考研] 328化工專碩求調(diào)劑 +4 | 。,。,。,。i 2026-03-12 | 4/200 |
|
|
[考研] 一志愿山大07化學(xué) 332分 四六級已過 本科山東雙非 求調(diào)劑! +3 | 不想理你 2026-03-12 | 3/150 |
|
|
[論文投稿]
投稿問題
5+4
|
星光燦爛xt 2026-03-12 | 6/300 |
|