| 5 | 1/1 | 返回列表 |
| 查看: 1132 | 回復(fù): 3 | ||||
| 當(dāng)前只顯示滿足指定條件的回帖,點(diǎn)擊這里查看本話題的所有回帖 | ||||
smileheaven金蟲 (小有名氣)
|
[求助]
MATLAB非線性優(yōu)化擬合怎么改才正確
|
|||
|
想對(duì)函數(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 但是返回的錯(cuò)誤卻是 ??? 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) 請(qǐng)各位蟲哥蟲姐幫忙看看,謝謝啦 |

金蟲 (小有名氣)

榮譽(yù)版主 (著名寫手)
彩色掛圖
![]() |
專家經(jīng)驗(yàn): +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)驗(yàn): +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'); |

| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 083000學(xué)碩274求調(diào)劑 +9 | Li李魚 2026-03-26 | 9/450 |
|
|---|---|---|---|---|
|
[考研] 一志愿:西北大學(xué),英一數(shù)一408-284分求調(diào)劑 +5 | 12.27 2026-03-27 | 5/250 |
|
|
[考研] 309求調(diào)劑 +15 | 誰不是少年 2026-03-29 | 15/750 |
|
|
[考研] 289求調(diào)劑 +16 | 新時(shí)代材料 2026-03-27 | 16/800 |
|
|
[考研] 材料專碩調(diào)劑 +11 | 椰椰。 2026-03-29 | 11/550 |
|
|
[考研] 303求調(diào)劑 +7 | DLkz1314. 2026-03-30 | 7/350 |
|
|
[考研] 化學(xué)工程085602 305分求調(diào)劑 +25 | RichLi_ 2026-03-25 | 25/1250 |
|
|
[考研] 317求調(diào)劑 +10 | 蛋黃咸肉粽 2026-03-26 | 10/500 |
|
|
[考研] 295求調(diào)劑 +5 | wei-5 2026-03-26 | 5/250 |
|
|
[考研] 一志愿南航 335分 | 0856 | GPA 4.07 | 有科研經(jīng)歷 +8 | cccchenso 2026-03-29 | 8/400 |
|
|
[考研] 085600,材料與化工321分求調(diào)劑 +10 | 大饞小子 2026-03-28 | 10/500 |
|
|
[考博] 26申博自薦 +6 | whh869393 2026-03-24 | 6/300 |
|
|
[考研] 275求調(diào)劑 +15 | Micky11223 2026-03-25 | 20/1000 |
|
|
[考研] 321求調(diào)劑 +7 | 璞玉~~ 2026-03-25 | 8/400 |
|
|
[考研] 394求調(diào)劑 +3 | 好事多磨靜候佳?/a> 2026-03-26 | 5/250 |
|
|
[考研] 求調(diào)劑 +6 | 蘆lty 2026-03-25 | 7/350 |
|
|
[考研] 272求調(diào)劑 +7 | 腳滑的守法公民 2026-03-27 | 7/350 |
|
|
[考研] 274求調(diào)劑 +17 | 顧九笙要謙虛 2026-03-24 | 23/1150 |
|
|
[考研]
材料調(diào)劑
5+4
|
想要一壺桃花水 2026-03-25 | 10/500 |
|
|
[考研] 296求調(diào)劑 +4 | 汪?! 2026-03-25 | 7/350 |
|