PDA

View Full Version : Simultaneous equation using PIC assembly



mankan
- 6th September 2006, 13:07
Hello,

I am looking for a sample code to solve Simultaneous equation using PIC assembly.

I looking for solving x,y,z unknowns with 3 different sets of equcations.

Any help is appreciated.

Thanks,
Mankan

mankan
- 11th September 2006, 17:14
Hello PIC Gurus,

Any help regarding above topic is greatly appreciated.

TIA,
Mankan

paul borgmeier
- 11th September 2006, 19:16
Mankan,

I have done this (3 equ and 3 unkns) with brute force using Cramer's rule (which is "plug and chug" systematic). However, because we are working with integers, have variable size limits, and no easy way to track negative signs, you need to be careful not to "lose" your answer or get the wrong answer. Beyond Cramer's, you can search online for some form of "Gauss Elimination" for bucket loads of information on numerically solving simultaneous equations.

A quick 2eq and 2unkns example follows using Cramer's Method

Solve:
5x+3y=13
x+y=3
(answer: x = 2, y = 1)

'declare variables accrodingly - I did not
x1=5
y1=3
a1=13
x2=1
y2=1
a2=3

D = (x1*y2)-(x2*y1)
x = ((a1*y2)-(a2*y1))/D 'x=2 yeah!
y = ((x1*a2)-(x2*a1))/D 'y=1 yeah!
However, negatives and fractions must be dealt with or you will get a surprise answer and not the correct answer - this example had none. (3 equ and 3 unkns is similar but with lots more terms, which would means lots more checking for negative signs.)

Good and lots lots lots of Luck,