Solved

Sin with period not 2p

Posted on 2011-02-27
10
364 Views
Last Modified: 2012-05-11
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
Comment
Question by:allelopath
  • 4
  • 4
  • 2
10 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 34992453
t/period
0
 
LVL 84

Expert Comment

by:ozo
ID: 34992456
you want f(0)=sin(0), f(20000)=sin(2*PI)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34992471


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
 
LVL 47

Expert Comment

by:for_yan
ID: 34992490

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
 
LVL 1

Author Comment

by:allelopath
ID: 34992760
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 84

Expert Comment

by:ozo
ID: 34992832
You changed the definition of period between http:#a26851153 http:#a34992760
again, you want  f(0)=sin(0), f(20000)=sin(2*PI)
0
 
LVL 1

Author Comment

by:allelopath
ID: 34992890
>>you want  f(0)=sin(0), f(20000)=sin(2*PI)
So how would my method change to do that?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 34992907
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
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 34992915
I think you need to multiply by period, nit to divide by it
0
 
LVL 84

Expert Comment

by:ozo
ID: 34992970
> 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 38
VB6 Compile Compatibility Issue 4 40
python question 5 60
Birthdays 3 21
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now