Results 1 to 2 of 2
  1. #1
    jeffrey12 is offline Member
    Join Date
    Apr 2017
    Posts
    3
    Rep Power
    0

    Default 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. #2
    gozzy is offline Member
    Join Date
    Jan 2017
    Posts
    46
    Rep Power
    0

    Default Re: Help with solving an equation

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

Similar Threads

  1. Help with Equation
    By TJRedeemer in forum New To Java
    Replies: 11
    Last Post: 09-28-2013, 12:10 AM
  2. Solving a quadratic equation using java
    By Khanak in forum New To Java
    Replies: 6
    Last Post: 06-03-2013, 03:20 PM
  3. Replies: 4
    Last Post: 11-26-2012, 11:15 AM
  4. Help with equation
    By _Jk_ in forum New To Java
    Replies: 10
    Last Post: 03-17-2011, 08:15 PM
  5. equation
    By bobo67 in forum New To Java
    Replies: 5
    Last Post: 09-06-2010, 06:40 PM

Posting Permissions

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