Re: [問題] 解方程已回收
※ 引述《zupo (MATLAB程式編輯員)》之銘言:
: ※ 引述《bensou (**++Ben..)》之銘言:
: : 不好意思.我想問matlab怎樣解
: : -1=9*sin(x)/x+cos(x)
: : 我想求x->0~6pi的解.可以解嗎??
: : 有甚麼不妥請指出.感謝各位收看
: function pttex132
: clc
: h1 = fsolve(@trianglenl,1)
: h2 = fsolve(@trianglenl,5)
: h3 = fsolve(@trianglenl,8)
: h4 = fsolve(@trianglenl,11)
: h5 = fsolve(@trianglenl,14)
: h6 = fsolve(@trianglenl,17)
: h7 = fsolve(@trianglenl,20)
: function f = trianglenl(x)
: f = 9.*sin(x)./(x+eps)+cos(x)+1;
.... 當你用 matlab toolbox 之前, 請先想想這個題目的數學意義.
否則, 絕對是 G-I-G-O.
首先, 這個題目是 -1=9*( (sin(x)/x) + cos(x) )
還是 -1=9* sin(x) / ( x+cos(x) ) ?
如果你有 sin(x)/x 這一項, 那直接用 toolbox 會有不可預期的後果,
所以你必須考慮 eps = 1e-5;
然後試著在 [0,eps] and [eps, 6*pi] 之間討論.
另外, 這題其實沒那麼糟糕,
因為 -1/9 = ( sin(x) / x+cos(x) ) ;
你仔細看, sin, cos 都是 bounded in [-1,1] , 所以當 x 變大的話,
整個 sin(x) / (x + cos(x)) 的絕對值會被 bound 住,
你甚至可以找到一個 x-upper, 說明這個 function in x > x-upper 之後
絕對值是小於 1/9.
So, 你可以 build Cost function as
C(x) = { ( sin(x) / x+cos(x) ) - (-1/9) }^2,
然後用 牛頓法, 或是 Golden section 法
應該都能找到.
我喜歡用 fminsearch 作,
這題有幾個解, 其中一個 x = 2.11, 剩下的就是你的功課了.
--
趙客縵胡纓,吾鉤霜雪明。銀鞍照白馬,颯沓如流星。
十步殺一人,千里不留行。是了拂衣去,深藏身與名。
閑過信陵飲,脫劍膝前橫。將炙啖朱亥,持觴勸侯贏。
三杯吐然諾,五嶽倒為輕。眼花耳熱後,意氣素霓生。
就趙揮金錘,邯鄲先震驚。千秋二壯士,烜赫大梁城。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 128.125.20.198
討論串 (同標題文章)