# Thread: Help with solving an equation

1. Member
Join Date
Apr 2017
Posts
3
Rep Power
0

## Help with solving an equation

I wanted to find all of the solutions to sin(x^2) - cos(x^3) = 0 for 0<= x <= pi and have this program. I used the bisection method to find the first solution but obviously I want to find the other solutions as well. How can I modify it to display other solutions in addition to the single one it gives me?

Java Code:
```public class BisectionEquation {

public static void main(String[] args){
// error margin
final double step = 0.0000001;

// variables
double begin = 0; // range from 0 to pi
double end = 3.14159;
double mid;
double midFunc;
double beginFunc;

// bisection loop to find result
while ( (end-begin) > step ){
mid = (begin+end)/2; // middle value (halfway between begin and end values
midFunc = Math.sin(mid*mid) -Math.cos(mid*mid*mid); // function values at begin and mid
beginFunc = Math.sin(begin*begin) -Math.cos(begin*begin*begin);

// if solution is between beginning and middle
if ( (midFunc > 0 && beginFunc < 0) || (midFunc < 0 && beginFunc > 0) ){
// Set the new end as the middle
end = mid;
}
//if solution is between mid and end
else{
begin = mid;
}
}
//prints the solution
System.out.println("The first solution of x: " + (begin+end)/2 );
}
}```

2. Member
Join Date
Jan 2017
Posts
46
Rep Power
0

## Re: Help with solving an equation

Surely you'd be able to do it by simple iteration between 0<= x <= Pi?

#### Posting Permissions

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