Need expert helpâ€”fast? Use the Help Bell for personalized assistance getting answers to your important questions.

I want a sin function with a period of 20000.

The method below doesn't seem to work quite right.

What is wrong?

The method below doesn't seem to work quite right.

What is wrong?

```
private double getSine(int t) {
double amplitude = 5.0;
double period = 20000 / 2 * Math.PI;
double sin = amplitude * Math.sin(t + period);
return sin;
}
```

I think:

if you say

double a = (2*Math.PI)/2000.0;

then

sin(a*x) will have period of 2000

because

a*(x+2000) = a*x + 2pi

double a = (2*Math.PI)/2000.0;

double f0 = Math.sin(a*0);

double f1 = Math.sin(a*2000.0);

if(Math.abs( f0-f1) > 0.0000001)System.out.print

else

System out.println("This suggestion is correct!");

```
private double getSine(int t) {
double period = 2 * Math.PI / 20000;
double sin = Math.sin(t / period);
return sin;
}
```

Then I do:```
for (int t = 0; t <=20000; t+=1000) {
double sin = getSine(t);
System.out.println (t + "\t" + sin);
}
```

I get:

0 0

1000 -0.491569492

2000 -0.856155132

3000 -0.999575956

4000 -0.884783024

5000 -0.541430024

6000 -0.058213036

7000 0.440041734

8000 0.824623475

9000 0.996185761

10000 0.910410056

11000 0.589454223

12000 0.116228635

13000 -0.387021517

14000 -0.790294996

15000 -0.989416869

16000 -0.932949312

17000 -0.635479214

18000 -0.173850032

19000 0.332688662

20000 0.753286131

Which is not a period of 20000

again, you want f(0)=sin(0), f(20000)=sin(2*PI)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Open in new window