Page 1 of 1

12575 - Sin Cos Problem

Posted: Wed Dec 05, 2012 11:07 pm
by jrbustosm
I am getting the wrong answer, and do not know why, could you help me?

f (x) = A * sin (x) + B * sin (x) = R * cos (x-alpha)

where,

R = sqrt (A * A + B * B) = f (x) max

alpha = atan (A / B)

f '(x) = A*cos(x) - B*sin(x) = 0

=> A*cos(x_max) - B*sin(x_max) = 0
tan(x_max) = A/B
x_max = atan(A/B)

I have the following entry:

Code: Select all

12
1 1
-1 1
1 -1
-1 -1
-5 0
5 0
0 -5
0 5
165 267
-165 267
165 -267
-165 -267
and the following output:

Code: Select all

0.79 1.41
5.50 1.41
2.36 1.41
3.93 1.41
4.71 5.00
1.57 5.00
3.14 5.00
0.00 5.00
0.55 313.87
5.73 313.87
2.59 313.87
3.70 313.87

Re: 12575 - Sin Cos Problem

Posted: Thu Dec 06, 2012 4:11 pm
by morris821028
A = 0 B = 0
should output
0.00 0.00

atan(A/B) will happen error.
maybe use atan2()

???????

Re: 12575 - Sin Cos Problem

Posted: Thu Dec 06, 2012 5:35 pm
by jrbustosm
Thanks at lot, the error I had was just that you said

Re: 12575 - Sin Cos Problem

Posted: Sat Sep 06, 2014 3:02 pm
by lighted
One tricky thing is that i got WA when wrote like this. :-?

Code: Select all

if (alpha < 0) alpha += pi * 2;
Got acc when changed to

Code: Select all

if (alpha < -eps) alpha += pi * 2;