# Thread: Totally lost. How do I do these seemingly easy mathematical functions in Java?

1. Member
Join Date
Feb 2013
Posts
7
Rep Power
0

## 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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## 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

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

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

Thanks Jim.

#### Posting Permissions

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