• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Sin with period not 2p

I want a sin function with a period of 20000.
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;
}

Open in new window

0
allelopath
Asked:
allelopath
  • 4
  • 4
  • 2
2 Solutions
 
ozoCommented:
t/period
0
 
ozoCommented:
you want f(0)=sin(0), f(20000)=sin(2*PI)
0
 
for_yanCommented:


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




0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:

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.println("This suggestion is wrong!");
else
System out.println("This suggestion is correct!");
0
 
allelopathAuthor Commented:
I don't think any of these are correct. First for simplicity, let's remove the amplitude:
private double getSine(int t) {
	double period =  2 * Math.PI / 20000;
	double sin = Math.sin(t / period);
	return sin;
}

Open in new window

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

Open in new window


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


0
 
ozoCommented:
You changed the definition of period between http:#a26851153 http:#a34992760
again, you want  f(0)=sin(0), f(20000)=sin(2*PI)
0
 
allelopathAuthor Commented:
>>you want  f(0)=sin(0), f(20000)=sin(2*PI)
So how would my method change to do that?
0
 
for_yanCommented:
this one works

public class MySine{
public MySine(){

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

private double getSine(int t) {
	double period =  (2 * Math.PI) / 20000.0;



    System.out.println("number " + ( t* period));




     System.out.println("number " + ( t*period));

    double sin = Math.sin(t*period);
	return sin;
}
public static void main(String [] args){
new MySine();    
}
}

Open in new window

0
 
for_yanCommented:
I think you need to multiply by period, nit to divide by it
0
 
ozoCommented:
> I think you need to multiply by period, nit to divide by it
that depends whether you use
double period = 20000 / 2 * Math.PI;
or
double period =  2 * Math.PI / 20000;

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now