12575 - Sin Cos Problem

All about problems in Volume 125. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
jrbustosm
New poster
Posts: 6
Joined: Tue Oct 09, 2012 9:18 pm

12575 - Sin Cos Problem

Post 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
morris821028
New poster
Posts: 13
Joined: Thu Dec 06, 2012 4:07 pm

Re: 12575 - Sin Cos Problem

Post by morris821028 »

A = 0 B = 0
should output
0.00 0.00

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

???????
?? Taiwan ! ??????????
jrbustosm
New poster
Posts: 6
Joined: Tue Oct 09, 2012 9:18 pm

Re: 12575 - Sin Cos Problem

Post by jrbustosm »

Thanks at lot, the error I had was just that you said
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12575 - Sin Cos Problem

Post 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;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 125 (12500-12599)”