Jump to content

What is this function ?

Featured Replies

Dear All,

 

I'm trying to find function J(x) shown in attached file. Could somebody help me ? It seems that I don't have the right tool to solve it :doh:

 

Thanks and Regards.

 

 

Série.pdf

That capitol Sigma is a summation of the function of P for all values of P between 0 and infinity. Not sure how to solve it though - I haven't done that for years. I'm sure someone else can point you in the right direction - there are some good maths guys here. :)

Not sure how to solve it though

 

It is an infinite loop.

public static void function(int x){
  int answer = 0;
  int p = 0;
  while(true){
    if(p%2 == 0}{
​       answer = answer + java.lang.Math.pow((x/2),​2p)/java.lang.Math.pow(factorial(p),2)
       system.out.println(answer);
    } else{
       answer = answer - java.lang.Math.pow((x/2),​2p)/java.lang.Math.pow(factorial(p),2)
​​       system.out.println(answer);
    }
  }

}

public static int factorial(int n) {
   int result = 1;
   for (int i = 1; i <= n; i++) {
      result = result * i;
   }
   return result;
}

It is an infinite loop.

It is the sum of an infinite series, which is not the same thing. Your program can never return the value of the function but it is often possible to calculate the value.

You seem to have missed modifying p. And, I'd recommend decreasing the repeated code.

 

Also, the code will "explode" when the ints start overflowing. It won't be infinite!

 

Points for a non-recursive factorial. However, since we know (well, I'm assuming) p increases by 1 each time, we'd be able to keep the last factorial calculated and just multiply by the new p each time, rather than re-calculating all of 1 to p each time. Of course that makes it a non-generic factorial function, more of a "nextvalue" function. (I didn't make this change).

 

(Disclaimer: I didn't read the PDF, I'm just reacting to the code (and I don't "do" java).)

 

 

public static void function(int x){
  int answer = 0;
  int temp = 0;
  int p = 0;
  while(true){
    temp = java.lang.Math.pow((x/2),​2p)/java.lang.Math.pow(factorial(p),2);
    if(p%2 == 0}{
​       answer = answer + temp;
    } else{
       answer = answer - temp;
    }
    system.out.println(answer);
    p++; // p was not changing
  }
}

public static int factorial(int n) {
   int result = 1;
   for (int i = 1; i <= n; i++) {
      result = result * i;
   }
   return result;
}

 

Edited by pzkpfw

  • Author

Dear All,

 

Thank you for your respective contributions. I do appreciate ! the reason why I need this function is because I need to integrate it in function of x.

 

Have your codes been typed on Matlab ? Do I need module "Symbolic Math Toolbox" to try your code ?

 

Thanks again and Regards,

Cédric

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.