|
Main menu
Resources
|
Bisection Method in Embedded Systems Abstract This article explains how to apply a bisection method in embedded systems, in order to avoid division of integer numbers. There are also mentioned: precision vs. speed tradeoff, and splitting of a nonlinear function into linear subranges. Included sample program in C, simulates calculation process and analysis of the maximum error. by Nedko Iliev, posted:2006.08.07 We take into consideration some non-linear function y=f(x) in a given argument range (a0,a4). The goal of the target program, running on a microcontroller is calculation of y with predictable accuracy. First we split the entire argument range into several subranges [ai,ai+1], then we replace each part of the real function by a line g(x), so f(ai)=g(ai)=bi and f(ai+1)=g(ai+1)=bi+1 as it is shown on Fig.1
The linear function g(x) is expressed by the following equations:
We split the subrange along each axis in two equal parts, defining new subranges that are twice smaller. Thus for [ai,ai+1] and [bi,bi+1] we obtain their middle points x1=((ai+ai+1)/2) and y1=((bi+bi+1)/2), accordingly. Then we compare the given value xc with the middle of the initial subrange x1. If (x1>xc) then we assume for the next step new subrange [ai;x1] for x-axis, and [bi;y1] for y-axis, otherwise we shall assume the other new subranges, i.e. [x1;ai+1] and [y1;bi+1]. We continue splitting and comparison process, until we obtain a middle point on the x-axis exactly equal to xc or reach certain limit of iterations (splitting and comparison). Of course the last obtained value for y-axis is the value we seek, and we should expect that it is not exact value of the function. Obviously we replace the arbitrary division by additions, comparisons and divisions by 2, and the last one is simply a shift-right operation for a microcontroller. Download sample code bisection.zip (5KB) You can mail your questions or comments to: Copyright (C) 2005, 2006 embedeo.com - Tems of Use and Legal Disclaimer |