精華區beta MATLAB 關於我們 聯絡資訊
※ 引述《Gwaewluin (神無月 孝臣)》之銘言: : ※ 引述《mogimnum (muwahahahaha)》之銘言: : : function F = myfun(x,a) : : F = [2*x(1) - x(2) - exp(-x(1)); : : -x(1) + a*x(2) - exp(-x(2))]; : : %======================================= : : a=2; : : x0 = [-5; -5]; % Make a starting guess at the solution : : options=optimset('Display','iter'); % Option to display output : 在fsolve這行上面要先打a為多少 : 譬如a = 1 ; : : [x,fval] = fsolve(@myfun,x0,options) % Call optimizer : ^^^^^^改為@( x )myfun( x , a ) : : 因為我function有變數a : : 我要怎樣把a值代入function : : 又可解出x 那個錯誤訊息指的是你指令括號沒標好 可能哪邊有多或是哪邊有少 不是指指令使用錯誤 而我跑是沒有問題的(7.5版) 請再檢查你的程式裡面的括號 函式 function F = myfun0117( x , a ) F = [ 2 * x( 1 ) - x( 2 ) - exp( - x( 1 ) ) ; - x( 1 ) + a * x( 2 ) - exp( - x( 2 ) ) ] ; 主程式 a = 2 ; x0 = [-5 ; -5 ] ; % Make a starting guess at the solution options = optimset( 'Display' , 'iter' ) ; % Option to display output [ x , fval ] = fsolve( @( x )myfun0117( x , a ) , x0 , options ) 運算結果 Norm of First-order Trust-region Iteration Func-count f(x) step optimality radius 0 3 47071.2 2.29e+004 1 1 6 12003.4 1 5.75e+003 1 2 9 3147.02 1 1.47e+003 1 3 12 854.452 1 388 1 4 15 239.527 1 107 1 5 18 67.0412 1 30.8 1 6 21 16.7042 1 9.05 1 7 24 2.42788 1 2.26 1 8 27 0.032658 0.759511 0.206 2.5 9 30 7.03149e-006 0.111927 0.00294 2.5 10 33 3.29525e-013 0.00169132 6.36e-007 2.5 Optimization terminated: first-order optimality is less than options.TolFun. x = 0.5671 0.5671 fval = 1.0e-006 * -0.4059 -0.4059 -- Deserves death! I daresay he does. Many that live deserve death. And some die that deserve life. Can you give that to them? Then be not too eager to deal out death in the name of justice, fearing for your own safty. Even the wise cannot see all ends. Gandalf to Frodo -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.25.235
hilosi:辛苦你了.... 01/17 13:21
mogimnum:謝謝你 我後來發現6.5版的不行 01/17 21:01