Full Version : Fractional Multiply
avr >>COMPUTER MATH >>Fractional Multiply


piheevo- 07-07-2006
Hi. I have got a simple question to a difficult problem:
I need to simulate an equation:

y = -0,5513x2 + 10,1564x1 + 10,0109x0

and display a solution (y) on the LCD (2x16)screen (I know the basic procedure to display registers).

x - time (display every second), x=(0...255), I don't need more.

1. Could anyone help me how to calculate it?
2. I programm in assembler.

THANK YOU!!!

RetroDan- 09-13-2006
You didn't mention how accurate you need the result to be.

I am assuming that your equation is:
QUOTE

           Y = -0.5513X^2 + 10.1564X + 10.0109

First you need to eliminate any decimals to eliminate the need for floating-point routines, so your equation would become:
QUOTE

    Y = ( -5513 x X^2 + 101564 x X + 100109 ) / 10000

In simplified psuedo-code it would be:
CODE

   TMP = 5513      ;TMP = 5513 x X^2
   MUL TMP,X
   MUL TMP,X

   ANS = 101564  ;ANS = 101564 x X
   MUL  ANS,X
         
   ADD ANS,100109;ANS = ((101564 x X) + 100109)
   SUB ANS,TMP1  ;ANS = (101564X+100109) - (5513X^2)
   DIV ANS,10000  ;ANS = ((101564X+100109)-(5513X^2)) / 10000

The answer would be the integer result of the final Division.
If you need the Fractional/Decimal portion, it is the remainder of last division.

Hope you find the above useful.

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.