Solved

Sin with period not 2p

Posted on 2011-02-27
10
405 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

691 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