Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sin with period not 2p

Posted on 2011-02-27
10
Medium Priority
?
417 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

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!

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

636 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