Calculating Math functions,from a sci.engineer's perspective.

Aug 28, 2009 7 Replies

Previous discussion in sci.math:



formatting link
________________



Sorry for interrupting (sci.engineers)



Question to sci.engineers:-


if you were assigned the task of designing a 'scientific calculator'



(a) How will you solve the problem of calculating the math functions?



(b) On what mathematical basis you will program the Microcontroller to calculate the math functions?


Examples :



(1) sinx; cosx; logx; {for different x values}



(2) d/dx cos(x) at x = 10



(3) Int 0_5 sinx dx


all-in-all to do..,



(i) Integration & Differentiation,



(ii) finding Root of a number, (iii) Finding fractional powers and all that.


Thanks for sharing:_o


Cell biology is the only science in which multiplication means the same thing as division.

Taylor polynomials. This is a simple operation on AVR let's say, and only a little more complicated on anything else (Z80?). AVR gets you an 8 bit multiply, so it takes a lot of accumulating, but that's understandable with ten digits or however many. The basic function is:

f(x) = (((A*x + B)*x + C)*x + D)*x + ...

where A, B, C, D, ..., are the usual polynomial coefficients, factored into the above running form. Use as many terms as are necessary for the desired accuracy. Since accuracy is fixed by the display's digits, this is easy to determine beforehand.

Notice that, for sin and cos, every other coefficient factor can be skipped, since only even or odd powers of x are necessary. Also, only values between

0 and pi/2 are necessary; the rest can be calculated from identities. The reduced range also simplifies the polynomial.

Constants, like e and pi, can of course be stored, though they can be calculated from power series (from the exp and atan functions, respectively).

Special attention might be paid to optimizing in BCD, since everything's going out to a decimal display anyway (unless you want to read floating point hex, which is certainly possible, but rather unconventional..).

As for integration, there are algorithms which compute them to arbitrary precision. No big deal here.

But really, I'd just buy a $10 calculator from the grocery store, because they've already done all that, and Idunno, it's probably all integrated into one ASIC anyway (probably programmed the same way though, no fancy math hardware like in a PC).

Tim

Deep Friar: a very philosophical monk. Website: http://webpages.charter.net/dawill/tmoranwms "matt" wrote in message news:h77r8q$qqc$1@aioe.org... > Previous discussion in sci.math: > > http://groups.google.com/group/sci.math/browse_thread/thread/088272ef78620b > 9f/f9f97672f00ac7bb?hl=en#f9f97672f00ac7bb > ________________ > > Sorry for interrupting (sci.engineers) > > Question to sci.engineers:- > > > if you were assigned the task of designing a \'scientific calculator\' > > (a) How will you solve the problem of calculating the math functions? > > (b) On what mathematical basis you will program the Microcontroller to > calculate the math functions? > > > Examples : > > (1) sinx; cosx; logx; {for different x values} > > (2) d/dx cos(x) at x = 10 > > (3) Int 0_5 sinx dx > > > all-in-all to do.., > > (i) Integration & Differentiation, > > (ii) finding Root of a number, > > (iii) Finding fractional powers and all that. > > > Thanks for sharing:_o > > -- > Cell biology is the only science in which multiplication > means the same thing as division.

I believe that HP used the Cordic algorithm to do those..

Yes indeed, and I just posted a couple of related docs in alt.binaries.schematics.electronics (aka ABSE).

Bob

== All google group posts are automatically deleted due to spam ==

This question has now been asked in too many groups and looks like someone trying to get a homework or exam assignment done without making any effort, cracking open a book or even googling.

Regards, Martin Brown

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0

s?

to

I have a few papers on the coordic since we used it in a modem DSP demod. Very powerful, but also very slow. I don't think it can find roots, fractional powers, integrate, and differentiate. I know you can multiply and divide with it.

One of the better sources I found on the cordic was a PHD thesis at Stanford The authors was Ahmed (not sure if first or last). It went into the algorithm in depth.

Over at Stanford's math library I found quite a few papers on the polynomial approach. The cordic is good for DSP because it is very compact. The math libraries don't use it since they are not concerned about code size.

As a compromise, I found papers written in the 1960's had some very compact algorithms for these computations. That is, not as bloated as modern software, should you need to put it in a uP.

You can write a coordic in maybe a page of C. It really shows how the code grinds out the answer.

If you are using a C compiler, but if you don't have floating point support, I would use something like this for floating point support:

formatting link

Then fdlibm for the rest:

formatting link

If you don't have a C compiler, port this one:

formatting link

Frank Buss, fb@frank-buss.de http://www.frank-buss.de, http://www.it4-systems.de

20b

=20

=20

I would actually use a selection of algorithms based on the value of the argument(s). Code space has become very low price, and scratchpad size has increased over time.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required