Solved

Sin with period not 2p

Posted on 2011-02-27
10
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 56
troubleshoot a python script 8 113
IntelliJ and Eclipse Neon 2 installations 4 65
Java List 4 73
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.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

737 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