Issue link: http://dc.ee.ubm-us.com/i/71837

PROGRAMMER'S TOOLBOX e Getting serious So I'll make a deal with you. Let's do this thing together. I'll give you an algorithm that seems to work on a limited number of cases. Feel free to try it out and let me know how it works. So I'll make a deal with you. Le t 's do this th ing togeth e r. I'll give you an a lgorithm th at seems to work o n a limited numbe r of cases. Feel free to try it o ut and le t me know how it LISTING I works. If you find pro blems wi th it, get bac k to me, and we' ll fi x it together. Between us, maybe we' ll a rrive at tha t ki ll er solutio n, after a ll. Deal? F.unctions for parabolic fit · . · .:':::i~~·~. ·. · II estimate a minimum via parabolic fit double para_f i t(double xO, double x1, double x2, double yO, double y1, double y2){ double n{) = (y1 - yO) I (x1 - xD>; double m1 = (y2 - y1)1(x2 - x1); double c = (m1 - n{))l (x2 - xD>; return (xQ + x1 - n{)lc>l2.0; } II shrink an interval using parabolic fit void para_shrink(double &xO, double &x1, double &x2, double &yO, double &y1, double &y2){ double x = para_fit(xO, x1, x2, yO, y1, y2); double y = f(x); if(x > x1 ){ swap(xO, x2); swap( yO, y2); swap(x, x1); swap(y, y1); } if(y > y1 ){ xO = x; yO = y; } else { x2 = x1; y2 = y1; x1 = x; y1 = y; } swap(xO, x2); swap(yO, y2 ); } Okay. We've pussyfooted around this issue for long enough. Let's put this sucker to bed. Befo re doing so, how- ever, maybe I should review the bid- ding. We've already seen, months ago, an algorithm that can reliably find a minimum of a single va ria ble by means of bisection. Bisection using the golden ratio turned out to work a li ttle better than halving in tervals. The problem with any bisection method is tha t it ta kes awhile to get the solution . We can expect each step to improve our solution by just half a bit. For improveme nt by a fac- to r of, say, 10,000 (typical fo r mini- mum-finde rs; solution to mach ine accuracy is not feas ible), th at means a ro und 24 to 26 itera tions. No t o ut- rageously ine ffic ie nt (did you catch th e fac t tha t brent . c, from Recipes, too k 19 on my sample pro blem?), but naturally we' d like to d o be tte r. A bette r approach is to use a qua- dra ti c me th od. Such me th ods involve fi tting a quad ratic thro ugh the three sma ll est points, and using tha t to estima te the minimum. A quadratic meth od do ubles the num- ber of signi ficant d igits fo r each ite r- ation . Once it gets near a solution, it homes in like a hound dog afte r a possum. To th e 104 accuracy, we fo und a soluti o n to o ur sample problem in seven ite ratio ns (nine func ti o n evalu atio ns, coun ting setu p of the ini tial conditions). Each approach has its advantages. The bisection method is tl1e workhorse, the bubble sort of minimum fmders. It may be slow, but it's sure. One nice fea- ture of bisection methods is that tl1ey don 't really care if the function in ques- tion is well-behaved or not. For exam- ple, the golde n section search will cheerful ly find the minimum of: (1) Such a function will dtive a quadratic metl1od crazy, because its derivative is discontinuous. Like most higher-order 40 SEPTEMBER 2000 Embedded Systems Programming

- September001
- September002
- September003
- September004
- September005
- September006
- September007
- September008
- September009
- September010
- September011
- September012
- September013
- September014
- September015
- September016
- September017
- September018
- September019
- September020
- September021
- September022
- September023
- September024
- September025
- September026
- September027
- September028
- September029
- September030
- September031
- September032
- September033
- September034
- September035
- September036
- September037
- September038
- September039
- September040
- September041
- September042
- September043
- September044
- September045
- September046
- September047
- September048
- September049
- September050
- September051
- September052
- September053
- September054
- September055
- September056
- September057
- September058
- September059
- September060
- September061
- September062
- September063
- September064
- September065
- September066
- September067
- September068
- September069
- September070
- September071
- September072
- September073
- September074
- September075
- September076
- September077
- September078
- September079
- September080
- September081
- September082
- September083
- September084
- September085
- September086
- September087
- September088
- September089
- September090
- September091
- September092
- September093
- September094
- September095
- September096
- September097
- September098
- September099
- September100
- September101
- September102
- September103
- September104
- September105
- September106
- September107
- September108
- September109
- September110
- September111
- September112
- September113
- September114
- September115
- September116
- September117
- September118
- September119
- September120
- September121
- September122
- September123
- September124
- September125
- September126
- September127
- September128
- September129
- September130
- September131
- September132
- September133
- September134
- September135
- September136
- September137
- September138
- September139
- September140
- September141
- September142
- September143
- September144
- September145
- September146
- September147
- September148
- September149
- September150
- September151
- September152
- September153
- September154
- September155
- September156
- September157
- September158
- September159
- September160
- September161
- September162
- September163
- September164
- September165
- September166
- September167
- September168
- September169
- September171
- September172
- September173
- September174
- September175
- September176
- September177
- September178
- September179
- September180
- September181
- September182
- September183
- September184
- September185
- September186
- September187
- September188
- September189
- September190
- September191
- September192
- September193
- September194
- September195
- September196
- September197
- September198
- September199
- September200
- September201
- September202
- September203
- September204
- September205
- September206
- September207
- September208
- September209
- September210
- September211
- September212
- September213
- September214
- September215
- September216
- September217
- September218
- September219
- September220
- September221
- September222
- September223
- September224
- September225
- September226
- September227
- September228
- September229
- September230
- September231