|
-
Oct 31st, 2002, 09:31 AM
#1
Thread Starter
Lively Member
Pure Interest: Has anyone ever written a prog which works out the value of a surd?
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.
-
Oct 31st, 2002, 11:00 AM
#2
Frenzied Member
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.
-
Oct 31st, 2002, 11:15 AM
#3
Thread Starter
Lively Member
-
Oct 31st, 2002, 01:00 PM
#4
Originally posted by esmerelda
Hehehe.
??
-
Oct 31st, 2002, 02:01 PM
#5
Thread Starter
Lively Member
That was a "I have brainache from all that mathematics jumble" type of hehehe...
:P
-
Nov 1st, 2002, 03:45 PM
#6
Frenzied Member
Yeh -
That's the kind of Yeh you get when you post in the Math Forum and expect a non-math answer....
-
Nov 1st, 2002, 03:55 PM
#7
Frenzied Member
Okay - so you don't like math how about code?
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.
-
Nov 2nd, 2002, 09:03 AM
#8
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|