#Help!

22 messages · Page 1 of 1 (latest)

random tundra
limpid pendantBOT
#

Hey, @random tundra!
Please remember to /close this post once your question has been answered!

random tundra
#

I don't understand how to write the second sigma

narrow forum
#
public class MathSinusFactorial {

    public static void main(String[] args) {
        int kNum = 12;
        double S = 0;
        double numerator = 0;
        int factorial = 1;
        for(int k = 1; k <= kNum ; k++) {
            factorial = 1;
            numerator = 0;
            for(int n = 1; n <= k ; n++) {
                factorial = factorial * n;
                numerator += Math.sin(k)*n;
            }
            S += numerator/factorial;
        }
        System.out.print("k = "+ kNum );
        System.out.println();
        System.out.print("Sum: "+ S);
    }

}
random tundra
#

THANKS

reef tusk
narrow forum
#

You cannot get k factorial from previous step. What is k factorial at each step you calculate in inside for loop and then divide by that number.

reef tusk
#
factorial = 1;
for(int k = 1; k <= kNum ; k++) {
            factorial *= k;
            numerator = 0;
            for(int n = 1; n <= k ; n++) {
                numerator += Math.sin(k*n);
            }
            S += numerator/factorial;
        }
narrow forum
#

Ok, agree

#

Is there any difference to the result?

reef tusk
#

Faster? I didn't run it.
And u have Math.sin(k)*n, but look like it must be Math.sin(k*n).

narrow forum
#

But yes, when factorial is outside it is a bit better

#

computer processor is not so overloaded

#

no. Sin takes only k Otherwise it should be in parentheses in problem formula

#

But do as you think it should be

reef tusk
#

For me sin kn look like sin(k*n) and n sin k look like n*sin(k) or sin(k)*n. And sin kn need parentheses sin(k)n to mean sin(k)*n.
Anyway @random tundra better know what his teacher mean.

narrow forum
#

result is different

#

and yes maybe you are right

#

when it is multiplication then paranthesis is not necessary. Only if k would be added to n

random tundra