Hello,

im trying to solve the following equation:

3x?-7x+2=0
a=3, b=-7 e c=2

(-7)?-4.3.2
49-24 = 25

;eax=3
;edx=-7
;ecx=2
;ebx=4

im putting this in a proc cause i never did it before and i'd like to learn

solve proc near

xor eax, eax
xor edx, edx
mov ebx, 4
mov eax, 3
mov ecx, 2

imul eax, ecx
imul eax, ebx ; eax = 24

mov edx, -7 ; (-7)? part, idont get -49 as i should :/ -7*2=-49, any idea ?
imul edx, 2

; here im gonna do the subtraction

ret
solve endp

if anyone could help, thanks a lot.
ps : i dont understand fpu nor mmx but if u'd like to show me how to do on these n\p i'll learn soon :)
Posted on 2002-02-16 11:45:17 by The Keeper
Correct me if, I'm wrong, are you solving for x?


if it is the answer is 2.
Posted on 2002-02-16 11:59:29 by stryker
I don't understand what is in eqution.
Could anybody to be so kind translating it in words.
Posted on 2002-02-16 12:20:47 by The Svin
Hi,

im using Bhaskara formula, i dont know the name of this equation in english, i guess its something like "second xxx equation"

3x?-7x+2=0

a=3, b=-7 e c=2

delta = (-7)?-4.3.2 = 49-24 = 25

hope things are clear now :)
Posted on 2002-02-16 12:24:00 by The Keeper
hmm looks like the quadratic formula: ax^2 + bx + c = 0


-> 3x^2 + (-7x) + 2 = 0
-> 3x^2 - 7x + 2 = 0
-> (3x - 1)(x - 2)

In this equation there are 2 answers:



-> 3x - 1 = 0 -> x - 2 = 0
-> 3x = 1 -> x = 2
-> x = 1/3



a=3, b=-7 e c=2


I'm not sure what the e meant. Tell me if I'm wrong.


It's very hard to make an FPU code out of it since this has 2 equations for the final answer. :confused: choose your flavor of the 2



ok for the first one(Assuming NumberOne == 1...)?

fild NumberOne
fidiv a
fstp Result
Posted on 2002-02-16 12:42:55 by stryker
(-7)? part

(-7)? part means square of (-7) ?
(-7) multiplies (- 7)?
then
mov eax,-7
imul eax
-7*2=-49

if you - 7 ^ 2 (-7 in power of 2) then it equals 49 ,not - 49.
So you calculating delta, not x, don't you?
Posted on 2002-02-16 13:27:47 by The Svin
umberg6007, sorry, e means and, i got it from a book and forgot to translate.

The Svin, my aim was to find delta i could do it

solve proc near

xor eax, eax
xor edx, edx
mov ebx, 4
mov eax, 3
mov ecx, 2

imul eax, ecx
imul eax, ebx
mov edi, eax

mov eax,-7
imul eax

sub eax, edi

; eax = delta

ret
solve endp

i know this isnt optimized, i've no idea how to optimize, well im new to win32asm and i sux at math, but i found it challenging trying to do some math exercises like this one in asm.

thanks to all.
Posted on 2002-02-16 15:04:15 by The Keeper
ax? + bx + c = 0,

http://www.purplemath.com/modules/quadform.htm
This PROC is for (b? - 4ac) part of the above.

edit: removed picture, replaced by link on author request.
Posted on 2002-02-16 15:50:00 by bitRAKE
bitRAKE :)

i knew u would POP

i wonder if the proc can be optimized ?
or a way i can pass the parameters to the call like

push a
push b
push c
call solve

:stupid:
dunno why i added this image but i identified myself with it :P
Posted on 2002-02-16 16:05:14 by The Keeper
Thanks, Rake.
Now I finally get it :)
Posted on 2002-02-16 16:26:01 by The Svin
FWIW, there is a proc to solve quadratics in the FPU chapter of the MASM6.1 manual.
Posted on 2002-02-16 16:35:34 by peterverstappen
the one above i gave is the quadratic equation not the quadratic formula :)

for the squareRoot(b^2 - 4ac):




[size=9]
finit
fld bV
fmul bV
fld four
fmul aV
fmul cV
fsub
fsqrt
fstp result

;The result should be 5


[/size]


multiply b with -1.




[size=9]

fld bV
fmul negOne
fstp bV


[/size]


now we must choose whether if we should go adding or subtracting




[size=9]

;This is adding

fld bV
fadd result
fstp result

[/size]





[size=9]

;This is subtracting

fld bV
fsub result
fstp result

[/size]


then we divide by 2a




[size=9]
fld result
fld two
fmul aV
fdiv
fstp result

[/size]


if you go with subtracting you should have an answer of 0.333 . If addition it should be 2. Here's an attached program to do just that. Though this one is not well optimized, it should do the job for you.

Happy Coding!!!
Posted on 2002-02-16 16:57:01 by stryker
thanks for the code, i was just playing a little.
Posted on 2002-02-16 19:50:40 by The Keeper
Just last week i wrote a small program to find the roots of a quadratic. I've attached it, but it's not pretty.

Just note that it's a console app, so either:
- use the RadAsm project file i included
- build it with the makefile included, 'makefile quad'
- build it on your own

I'll repeat it's not very pretty, but it does account for all three possible cases for the roots.

malone
Posted on 2002-02-18 21:14:59 by malone
Come on malone, you must be joking! That code is fairly neat, and easily read. I like the constructive use of macros - kind of self-documenting. Good work!
Posted on 2002-02-18 23:11:55 by bitRAKE
Thanks for the encouragement bitRake :)

malone
Posted on 2002-02-19 09:13:36 by malone