Results 1 to 8 of 8

Thread: Pure Interest: Has anyone ever written a prog which works out the value of a surd?

  1. #1

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68

    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.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  3. #3

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    Hehehe.

  4. #4

  5. #5

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    That was a "I have brainache from all that mathematics jumble" type of hehehe...

    :P

  6. #6
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Yeh -

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


  7. #7
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  8. #8

    Thread Starter
    Lively Member esmerelda's Avatar
    Join Date
    Sep 2002
    Location
    South Croydon, UK
    Posts
    68
    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
  •  



Click Here to Expand Forum to Full Width