Prev: Zip question: Where are all the extra characters coming fromupon unzipping?
Next: SwingWorker threading issue?
From: harryos on 28 Oct 2009 05:07 hi I was trying to calculate the value of x(t)=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)+cos(2*pi*100*t) for some values.I wrote this code .... public static void main(String[] args) { double m1=0.0; double m2=0.0; double m3=0.0; double m4=0.0; double y=0.0; for(int t=0;t<3;t++){ debug("t="+t); m1=Math.cos(Math.PI*2*10*t); m2=Math.cos(Math.PI*2*25*t); m3=Math.cos(Math.PI*2*50*t); m4=Math.cos(Math.PI*2*100*t); y=m1+m2+m3+m4; System.out.println("m1="+m1); System.out.println("m2="+m2); System.out.println("m3="+m3); System.out.println("m4="+m4); System.out.println("y="+y); } } .... however ,I got the following output t=0 m1=1.0 m2=1.0 m3=1.0 m4=1.0 y=4.0 t=1 m1=1.0 m2=1.0 m3=1.0 m4=1.0 y=4.0 t=2 m1=1.0 m2=1.0 m3=1.0 m4=1.0 y=4.0 ----- I don't understand this..For example, the value of cos(2*pi*10*1) should be cos 62.832 which is .4566 .Instead I am getting the value 1. can somebody help me find out if I am doing something wrong? thanks harry
From: Arved Sandstrom on 28 Oct 2009 05:13 harryos wrote: > hi > I was trying to calculate the value of > x(t)=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)+cos(2*pi*100*t) for > some values.I wrote this code [ SNIP ] > I don't understand this..For example, the value of cos(2*pi*10*1) > should be cos 62.832 which is .4566 .Instead I am getting the value 1. > can somebody help me find out if I am doing something wrong? > thanks > harry You'll get dozens of answers here, but I see none posted yet - the argument is in radians, not degrees. So cos (20pi) = 1. AHS
From: harryos on 28 Oct 2009 05:42 On Oct 28, 2:13 pm, Arved Sandstrom <dces...(a)hotmail.com> wrote: the argument is in radians, not degrees. So cos (20pi) = 1. > AHS thanks for the reply.. if I use m1=Math.cos(Math.PI*2*10*t*180/Math.PI) will that do the conversion? harry
From: Lars Enderin on 28 Oct 2009 05:47 harryos wrote: > On Oct 28, 2:13 pm, Arved Sandstrom <dces...(a)hotmail.com> wrote: > the argument is in radians, not degrees. So cos (20pi) = 1. >> AHS > > thanks for the reply.. > if I use > > m1=Math.cos(Math.PI*2*10*t*180/Math.PI) > > will that do the conversion? > What's the point of multiplying, then dividing, with PI? If t is in degrees, you need to multiply with PI/180 to get radians.
From: Andreas Leitgeb on 28 Oct 2009 08:06 harryos <oswald.harry(a)gmail.com> wrote: > On Oct 28, 2:13 pm, Arved Sandstrom <dces...(a)hotmail.com> wrote: > > the argument is in radians, not degrees. So cos (20pi) = 1. > if I use m1=Math.cos(Math.PI*2*10*t*180/Math.PI) > will that do the conversion? If with 20pi you really thought of an angle in degrees, (that would be slightly larger than the angles of an equilateral triangle), then Math.PI*2*10*t*180/Math.PI or just: 3600*t does it. Usually it doesn't make any sense in real world to use Pi-multiples (like 20pi), interprete them as degrees and then convert them to radians to feed to trigonometric functions, but if you're just playing around, then such a sense is of course not a necessity.
|
Next
|
Last
Pages: 1 2 Prev: Zip question: Where are all the extra characters coming fromupon unzipping? Next: SwingWorker threading issue? |