Results 1 to 11 of 11

Thread: Calculus & java

  1. #1
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default Calculus & java

    yesterday i was study calculus " An Increasing / decreasing seq " ..

    in calculus we solve these problems as following :

    given (an), and find if sequences is Inc or Dec.
    we have to find an+1 first .
    then divide an+1/an ..
    if the result < 1 so it is decreasing , otherwise it is increasing.
    i solved many problems with many cases .. factorial , exponential functions .. etc . I said to myself .. if i have program to make my life easier and give me the answer directly that will save my time .. and my effort :rolleyes: .

    i thought about this program starting by solving simple problem for example:
    an = n .
    an+1 = n+1
    an+1/an = n+1/n .... n+1 > n .. so that it is increasing .
    if i could write this program .. then i believe i can write complex cases
    such as factorial , ..etc.

    Now ,

    input is an .. which user give to the program .
    of course ! input maybe n or n+1 , n+2 .. etc.
    but what i have focus on is replace each n by( n+1 ) !

    this what i did until now ! , because i started programming using java script , and am just little bit confused about java .. please tell me does until
    now am on the line .. give me yours advice to improve myself ..
    am stack little bit .. but i believe i can complete this program.



    Java Code:
        public static void main(String[] args) {
            // TODO code application logic here
            Scanner input = new Scanner(System.in);
            System.out.println("Please Enter the an");
            String an = input.nextLine();
            System.out.println("your an is"+"["+an+"]");
            int a = an.length();
            System.out.println("the an length is"+"["+a+"]");
            char []arr=an.toCharArray();
            String aa = "n+1";
    
            for(int index=0;index<arr.length;index++)
            {
            System.out.println("the CharArray is"+"["+arr[index]+"]");
            }
                for(int i =0;i<arr.length;i++)
    
                    if(an.charAt(i)=='n')
                    {
                    System.out.println("the new is"+"["+aa+"]");
                    }
                    else
                    {
                    System.out.println("the new is"+"FAILED ");
                    }
        }
    Last edited by SHE; 03-28-2011 at 03:29 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,383
    Blog Entries
    7
    Rep Power
    20

    Default

    Can you please tell us in ordinary words what you're trying to do because I (we) understand zilch from your code ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    Program determine whether the sequence Increasing or Decreasing.

    The input of program is : an.
    [an] should contain (n) !

    steps to determine whether this input is Increasing or Decreasing.
    1. count an+1 .. by replace each n by n+1 ..
    for example if an = n+1 , an+1 = (n+1)+1= n+2 and so on.
    .
    .

    step two :
    divide an+1/an ..
    case one if the result < 1 // it is decreasing , other wise .. it is increasing.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,383
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by SHE View Post
    Program determine whether the sequence Increasing or Decreasing.

    The input of program is : an.
    [an] should contain (n) !

    steps to determine whether this input is Increasing or Decreasing.
    1. count an+1 .. by replace each n by n+1 ..
    for example if an = n+1 , an+1 = (n+1)+1= n+2 and so on.
    .
    .

    step two :
    divide an+1/an ..
    case one if the result < 1 // it is decreasing , other wise .. it is increasing.
    Do you want to do it all symbolically? If you want to do it numerically all you have to check is whether or nor the next entry is larger than the current entry ... I still think I don´t understand what you want to do ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    let's take an = n + 1
    an+1 will be = n+2
    an+1/an = n+2/n+1 .. you can notice now ( an+1 )is greater than (an ) .. so it is increasing , this simplest case for these problems.
    .
    .
    so now i faced two things :
    1. the input will be String .. , if i replace each n by n+1 , after the operation how i can sum the numbers when the input is String , so that i thought about the char Array !
    but i still can't sum the numbers and keep the n . ( this the first thing which i want to know .. and i think after that i can do the step two)

    I hope you understand my point ^^"

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,383
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by SHE View Post
    let's take an = n + 1
    an+1 will be = n+2
    an+1/an = n+2/n+1 .. you can notice now ( an+1 )is greater than (an ) .. so it is increasing , this simplest case for these problems.
    .
    .
    so now i faced two things :
    1. the input will be String .. , if i replace each n by n+1 , after the operation how i can sum the numbers when the input is String , so that i thought about the char Array !
    but i still can't sum the numbers and keep the n . ( this the first thing which i want to know .. and i think after that i can do the step two)

    I hope you understand my point ^^"
    Ok, give us a few examples of what you want to type as the input for your program; I suspect that you want to do this symbolically.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    i already putted this example :


    let's take an = n + 1
    an+1 will be = n+2
    an+1/an = n+2/n+1
    anyway this another example :
    the input (n+3)/(n+2)
    because these operations about sequences so we need to know what is after this input.
    so that program will replace each n by (n+1).. the output which display to the user
    should be as following n+4/n+3 .. this first step.

    let's see my code :

    Java Code:
            Scanner input = new Scanner(System.in);
            System.out.println("Please Enter the an");
            String an = input.nextLine();
            System.out.println("your is"+"["+an+"]");
            [COLOR="Red"]// HERE THE PROGRAM  WILL TAKE THE INPUT FROM USER. [/COLOR]
            char []arr=an.toCharArray();
            [COLOR="Red"]// Now i putted the input to char array to be able to me change each n . [/COLOR]
            String aa = "n+1"; // an+1 is constant.
    But Then ...
    I MADE THESE CHANGES WHICH ARE WRONG , THAT IN RED ....
    Java Code:
            Scanner input = new Scanner(System.in);
            System.out.println("Please Enter the an");
            String an = input.nextLine();
            System.out.println("your is"+"["+an+"]");
            char []arr=an.toCharArray();
            [COLOR="Red"]char A ='n'+'1';[/COLOR]
            System.out.println(A);
            for(int index=0;index<arr.length;index++)
            {
            System.out.println("the CharArray is"+"["+arr[index]+"]");
            }
                for(int i =0;i<arr.length;i++)
    
                    if(an.charAt(i)=='n')
                    {
                     char a = an.charAt(i);
                    [COLOR="Red"] an.replace(a,A);[/COLOR]
                    }
                    else
                    {
                    System.out.println("the new is"+"?????");
                    }
        }

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,383
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by SHE View Post
    i already putted this example :



    anyway this another example :
    the input (n+3)/(n+2)
    because these operations about sequences so we need to know what is after this input.
    so that program will replace each n by (n+1).. the output which display to the user
    should be as following n+4/n+3 .. this first step.
    Hold it for a minute; if your input is "(n+3)/(n+2)" and you replace each "n" by "n+1", you get "(n+1+3)/(n+1+2)"; it takes a lot more logic to find out that you want "(n+4)/(n+3)". And what if the input was "n/2"; if you replace each "n" by "n+1" you get "n+1/2" which is totally wrong ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    yeah this logic is what am asking about .. which i have no idea about how i can implement it in java.

    if input n/2 .. output will n+1/2 .. !

    step two .. i have to divide n+1/2 / n/2 .. and then i have do the multiplication .. will get
    n+1/2 * 2/n & the final answer is .. n+1/n .. after if statement will find that
    input is increasing.

    so that i said what i want to try it now is simple case if it is work then i have to think
    in other cases ... there is sin , cos , factorial .. etc.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,383
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by SHE View Post
    yeah this logic is what am asking about .. which i have no idea about how i can implement it in java.

    if input n/2 .. output will n+1/2 .. !

    step two .. i have to divide n+1/2 / n/2 .. and then i have do the multiplication .. will get
    n+1/2 * 2/n & the final answer is .. n+1/n .. after if statement will find that
    input is increasing.

    so that i said what i want to try it now is simple case if it is work then i have to think
    in other cases ... there is sin , cos , factorial .. etc.
    So after 10 replies or so we can conclude that you want to solve this problem symbolically and you have no idea how to do it, right? I can tell you that a textual substitution, as your tried, is never going to work. You need to know the 'depth structure' of the expression, so you need to parse the textual representation and generate an AST (Abstract Syntax Tree) from it. Only then you can substitute the expression n+1 for the sub-expression n.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    SHE
    SHE is offline Member
    Join Date
    Mar 2011
    Posts
    27
    Rep Power
    0

    Default

    Ops ! so do you know good references (books, websites .. etc) which i can learn more about textual representation and generate an AST

Similar Threads

  1. For the people who love Calculus
    By tim in forum Forum Lobby
    Replies: 9
    Last Post: 12-01-2009, 12:53 PM
  2. How to best design a calculus solver
    By xcallmejudasx in forum New To Java
    Replies: 4
    Last Post: 06-25-2009, 05:27 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
  •