PDA

Click to See Complete Forum and Search --> : Pure Interest: Has anyone ever written a prog which works out the value of a surd?


esmerelda
Oct 31st, 2002, 08:31 AM
A surd is a square root that's not doable in yor head. They're usually returned by quadratic equations. HAS anyone ever written a prog to work the quadratic equations out AND square root the results?

Just interested.

jim mcnamara
Oct 31st, 2002, 10:00 AM
UM.

A surd is an irrational number defined as

( P +/- sqrt(D) ) / Q

where Q is a squarefree integer, and P, D are integers.
A squarefree integer is one that, when factored, has no duplicate
prime factors (prime number qualify), ie., 15 is squarefree (3 x 5), 54 is not ( 3 x 3 x 3 x 2 )

And, several people have posted versions of the quadratic formula
in VB. No one has posted the alternate form used where the usual version may give inaccurate result for one of the roots:

b2 >> 4ac

It's more involved to create a completely general solution.

esmerelda
Oct 31st, 2002, 10:15 AM
Hehehe.

NotLKH
Oct 31st, 2002, 12:00 PM
Originally posted by esmerelda
Hehehe.

??
:)

esmerelda
Oct 31st, 2002, 01:01 PM
That was a "I have brainache from all that mathematics jumble" type of hehehe...

:P

jim mcnamara
Nov 1st, 2002, 02:45 PM
Yeh -

That's the kind of Yeh you get when you post in the Math Forum and expect a non-math answer....

:D

jim mcnamara
Nov 1st, 2002, 02:55 PM
Okay - so you don't like math how about code?


PROGRAM QuadraticEquation
IMPLICIT NONE

REAL :: a, b, c
REAL :: d
REAL :: root1, root2

! read in the coefficients a, b and c

READ(*,*) a, b, c
WRITE(*,*) 'a = ', a
WRITE(*,*) 'b = ', b
WRITE(*,*) 'c = ', c
WRITE(*,*)

! compute the discriminant d

d = b*b - 4.0*a*c
IF (d > 0.0) THEN ! distinct roots?
d = SQRT(d)
root1 = (-b + d)/(2.0*a) ! first root
root2 = (-b - d)/(2.0*a) ! second root
WRITE(*,*) 'Roots are ', root1, ' and ', root2
ELSE
IF (d == 0.0) THEN ! repeated roots?
WRITE(*,*) 'The repeated root is ', -b/(2.0*a)
ELSE ! complex roots
WRITE(*,*) 'There are no real roots!'
WRITE(*,*) 'Discriminant = ', d
END IF
END IF

END PROGRAM QuadraticEquation


It's FORTRAN but other than READ() WRITE(), a VB'er should be able to read the thing and translate it into VB. ALthough why you'd want to go to a really slow language for math routines I don't know.

esmerelda
Nov 2nd, 2002, 08:03 AM
LOL.

I just wondered, it was just a question "Has anyone written one" not "Can someone give me the code for one" I was just interested, that's all...

:P