Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    Default Totally lost. How do I do these seemingly easy mathematical functions in Java?

    How do I do this in Java?

    Java Code:
    Center points 1,1 & 2,2
    (One and two lines below are the equation of two circles)
    (x-1)^2 + (y-1)^2 = 1
    (x-2)^2 + (y-2)^2 = 1
    
    Do all the operations of the above equations
    x^2 – 2x + 1 + y^2 – 2y + 1 = 1
    x^2 – 2x + 1 + y^2 – 2y = 0
    
    x^2 – 4x + 4 + y^2 – 4y + 4 = 1
    x^2 – 4x + 7 + y^2 – 4y = 0
    
    Multiply one of the equations by -1
    -x^2 + 2x – 1 – y^2 + 2y = 0
    
    Add the equation that was multiplied by -1
     to the equation that wasn't multiplied by -1
    -2x + 6 – 2y = 0
    
    Put the above sum in terms of x
    -2x = 2y -6
    x = -y + 3
    
    Take the equation that was multiplied by -1
    before it was multiplied by -1 and substitute
    x for what x was found to equal in the above
    equation which was -y + 3
    (-y + 3)^2 – 2(-y + 3) + 1 + y^2 – 2y = 0
    
    Do all the operations of the above equation
    y^2 – 6y + 9 + 2y – 6 + 1 + y^2 – 2y = 0
    2y^2 – 6y + 4 = 0
    
    Use the quadratic formula to solve for y
    ax^2 + bx + c = 0
    a = 2 | b = -6 | c = 4
    y = ( -b + sqrt ( b^2 – 4ac ) ) / 2a
    y = ( -b – sqrt ( b^2 – 4ac ) ) / 2a
    Last edited by calculatingexistence; 05-07-2013 at 01:21 AM.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,390
    Rep Power
    5

    Default Re: Totally lost. How do I do these seemingly easy mathematical functions in Java?

    Native java has no ability to solve equations. So you need to either install a package for that purpose or use basic algebra and isolate one variable in terms of another. Then it's plug and chug.

    Also note:
    Multiplication is done by using *
    Exponentiation is done by using Math.pow()
    Square root is done by using Math.sqrt()

    ^ is bitwise exclusive or so don't use it for exponentiation

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Join Date
    Feb 2013
    Posts
    7
    Rep Power
    0

    Default Re: Totally lost. How do I do these seemingly easy mathematical functions in Java?

    Thanks Jim.

Similar Threads

  1. Mathematical functions
    By Stev in forum New To Java
    Replies: 14
    Last Post: 11-27-2010, 02:08 PM
  2. Totally lost with reading excel
    By nkk in forum New To Java
    Replies: 4
    Last Post: 09-13-2010, 10:15 AM
  3. I'm lost, totally(pointer exceptions?)
    By helpisontheway in forum New To Java
    Replies: 4
    Last Post: 12-01-2009, 06:41 AM
  4. Replies: 1
    Last Post: 09-04-2008, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •