Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


2 Pages12>
Options
Go to last post Go to first unread
Offline jofegibo  
#1 Posted : 22 April 2016 07:28:36(UTC)
jofegibo

Rank: Newbie

Groups: Registered
Joined: 22/04/2016(UTC)
Posts: 1
Colombia
Location: Cali

Hi, I am having some issues Here,
As my english is very bad, I prefer to show you the picture about my problem
SMath_Issue.png Solucionario 2 - Puntos Extra.sm (170kb) downloaded 35 time(s).

If I make step by step caculations, the answer is correct (Which is 19.47°Wink. When I try to make them using user functions, the answer is wrong even if I am using the same values for parameters.

Edited by moderator 07 October 2016 11:58:40(UTC)  | Reason: marked as fixed

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline mikekaganski  
#2 Posted : 22 April 2016 08:50:11(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
This is a bug.

The problem is triggered by your naming. You use x, y throughout your functions. It seems that actual parameters names interference with dummy parameters names. Here it's evident: arguments-bug.sm (3kb) downloaded 38 time(s).

To workaround, please change names of parameters in your functions, namely in atan2. E.g., you may make it atan2(yy;xx):= ....

Created SS-2327.
Best regards,
Mike Kaganski
thanks 1 user thanked mikekaganski for this useful post.
on 22/04/2016(UTC)
Offline Jean Giraud  
#3 Posted : 22 April 2016 22:12:20(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Your coding is not correct:

"atan2(x,y) => returns the angle in radian from the 'x' axis to a line
containing the ORIGIN [0,0] and the point [x,y]. The value returned is
always between -π and π including π. Both x,y must be real".

Forum atan2.gif
Offline mikekaganski  
#4 Posted : 23 April 2016 04:07:43(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Your coding is not correct:

"atan2(x,y) => returns the angle in radian from the 'x' axis to a line
containing the ORIGIN [0,0] and the point [x,y]. The value returned is
always between -π and π including π. Both x,y must be real".



Jean, you keep amusing me. Being a bright person, and making valuable contributions, you too often post either irrelevant or plain wrong comments, this one being both. It's wise to try to get some literacy in the topic before posting.

The coding of jofegibo is done letter-to-letter by definition given in Wikipedia (just above the "2.1 Derivation of atan2(y, x)" section), and is quite correct. It is somewhat redundant, as it's not necessary to check that y = 0 in subsequent conditions (it is already true since those conditions are in "else" clause of "if y!=0" ), but this doesn't do any harm.

Anyway, your comment is not only incorrect, but also irrelevant (as in other topics, too): the origial poster didn't ask advise on the coding, but made a well-defined question that highlights existing problem.

Please, try to refrain of irrelevant comments in every topic you happen to notice, just because it distracts those who have something to say on essence of the matter, and make it harder to search the forum for a relevant info.
Best regards,
Mike Kaganski
Offline CBG  
#5 Posted : 23 April 2016 05:37:54(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 308

Was thanked: 77 time(s) in 58 post(s)
MikeKaganky this right, changing the names of variables , solve the problem.


Cinematica_Inversa.png


Best Regards
Offline Jean Giraud  
#6 Posted : 23 April 2016 05:49:19(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
"atan2(x,y) => returns the angle in radian from the 'x' axis to a line
containing the ORIGIN [0,0] and the point [x,y]. The value returned is
always between -π and π including π. Both x,y must be real".

That definition is correct and universal. What's confusing is Smath built-in "mwatan2(,,)
That's why I posted an example for edu/observe. Otherwise Smath angle is even more simple:

x:=64.644 ,,,,, y:=135.355
arg(x+y*i)=64.471393°

'z' in the front end comes out of the blue. If it's further needed, and produces red ?
Maybe some info are missing about what is doing what for what.

Cheers, Jean.
Offline mikekaganski  
#7 Posted : 23 April 2016 06:07:17(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
"atan2(x,y) => returns the angle in radian from the 'x' axis to a line
containing the ORIGIN [0,0] and the point [x,y]. The value returned is
always between -π and π including π. Both x,y must be real".

That definition is correct and universal.

Yes, that's true. So what? OP's post conforms to this definition completely.

Quote:
What's confusing is Smath built-in "mwatan2(,,)
That's why I posted an example for edu/observe.

Oh, really?
Here you do two mistakes. First: mwatan2(,,) isn't SMath built-in. It's Matlab C++ Math Library extension's function.
Second: what you've posted wasn't presented as something "for edu/observe", as it started with:
Originally Posted by: Jean Giraud Go to Quoted Post
Your coding is not correct:

Btw, whos? A person who implemented Matlab's mwatan2? Does that belong here?

Edited by user 23 April 2016 06:38:30(UTC)  | Reason: Not specified

Best regards,
Mike Kaganski
Offline Jean Giraud  
#8 Posted : 23 April 2016 06:29:02(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Your atan2(y,x) is right with your Smath version.
But there is a bug in your version wrt to "atan2(,,)
the universal implementation and bug wrt Smath 5346
which version respects the maths adopted convention.

Forum atan2 WRONG.gif




Offline Jean Giraud  
#9 Posted : 23 April 2016 06:32:17(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... and by same token: mwatan2[,,] is bug in Smath 5346.
Two birds in one shot !
Offline mikekaganski  
#10 Posted : 23 April 2016 06:50:38(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Your atan2(y,x) is right with your Smath version.
But there is a bug in your version wrt to "atan2(,,)
the universal implementation and bug wrt Smath 5346
which version respects the maths adopted convention.

Forum atan2 WRONG.gif


Originally Posted by: Jean Giraud Go to Quoted Post
... and by same token: mwatan2[,,] is bug in Smath 5346.
Two birds in one shot !


Your own screenshot shows that there's NO error in mwatan(#,#). Maybe you were confused by the names of arguments?

By definition, atan2(y,x)≡arg(x+i*y)

Please notice that atan2 has y and x in "reversed" order.

What is "UNIVERSAL IMPLEMENTATION" of atan2? Link please.
Best regards,
Mike Kaganski
Offline Jean Giraud  
#11 Posted : 23 April 2016 13:35:15(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
By definition, atan2(y,x)≡arg(x i*y)

Please notice that atan2 has y and x in "reversed" order.

What is "UNIVERSAL IMPLEMENTATION" of atan2? Link please.



atan2(y,x)≡arg(x i*y)

Answer: WRONG, bug in your Smath version.

"Universal Implementation" of atan2 is as adopted since the very first day of FORTRAN,
respected in Mathcad 8/11 but not in your Smath version.

Polar Angles.bmp

Offline mikekaganski  
#12 Posted : 23 April 2016 13:46:22(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
"Universal Implementation" of atan2 is as adopted since the very first day of FORTRAN,
respected in Mathcad 8/11 but not in your Smath version.


Oh really?

Let's ask IBM, the Fortran inventor:
http://www.ibm.com/suppo...e_ref/atan2.html?lang=en

Your version of Mathcad uses non-standard definition, but that doesn't make it standard.
Best regards,
Mike Kaganski
Offline Jean Giraud  
#13 Posted : 23 April 2016 14:51:10(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
Your version of Mathcad uses non-standard definition, but that doesn't make it standard.


Ask Uni about his Mathcad version more recent than mine [8/11]

'tan' is Y/X we know that since ages. But polar angle is this way,
Both in Smath 5436 [correct] and Mathcad 8/11 also correct.
And the two are correct by the books.

A bug is a bug, end of it.

Forum Smath Polar Angle.gif

Offline mikekaganski  
#14 Posted : 23 April 2016 14:53:21(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Jean,
you are ignorant troll. End of it. I only ask you: please, don't ever bother to answer to my posts.
Best regards,
Mike Kaganski
Offline Jean Giraud  
#15 Posted : 23 April 2016 15:06:33(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: mikekaganski Go to Quoted Post
Jean,
you are ignorant troll. End of it. I only ask you: please, don't ever bother to answer to my posts.


Don't worry Mike, this kind of question will come again and again
as long as the bug is not cleared. My last post is the 1/1 Smath
to get the polar angle of a complex number, just replying the
very fisrt thread, not to you in particular. As you say: end of it.

Offline Ber7  
#16 Posted : 23 April 2016 16:27:19(UTC)
Ber7


Rank: Advanced Member

Groups: Registered
Joined: 15/07/2010(UTC)
Posts: 437
Man
Israel
Location: Beer-Sheva

Was thanked: 520 time(s) in 288 post(s)
atan2.sm (19kb) downloaded 29 time(s).Hi,jofegibo.

If you take the code from Wikipedia, the error will not
https://en.wikipedia.org...finition_and_computation

Offline mikekaganski  
#17 Posted : 23 April 2016 16:35:25(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
That's because of line() used.

Edit: no, I'm wrong.
Original function only works if its body os enclosed in eval(). Ber7's version works without line().

Edited by user 23 April 2016 16:52:11(UTC)  | Reason: Not specified

Best regards,
Mike Kaganski
Offline Jean Giraud  
#18 Posted : 23 April 2016 20:44:38(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... all that said: "Atan(y, x) = Arg(x + yi)"

Happy reconciliation.
Offline ur_naz  
#19 Posted : 26 April 2016 07:08:03(UTC)
ur_naz


Rank: Member

Groups: Registered
Joined: 06/04/2016(UTC)
Posts: 15
Location: Ukraine

Can anyone elucidate my why value of 'a' is changed to 0,0076 when calculated as 0,015? Shok

List1.sm (11kb) downloaded 32 time(s).
Offline mikekaganski  
#20 Posted : 26 April 2016 07:25:11(UTC)
mikekaganski


Rank: Advanced Member

Groups: Registered
Joined: 17/01/2013(UTC)
Posts: 296
Man
Russian Federation
Location: Khabarovsk, Russia

Was thanked: 151 time(s) in 107 post(s)
Oh! You scared me! Good

Actually, you should look what is actually assigned to a. To do so, just put caret at the beginning of the expression, and use right arrow to travel to the right. Keep attention to the underscore.
You'll see that it's only first part (sin(dlat/2))^2 that is actually assigned. Everything else is just added to the result of assignment:

(a:(sin(dlat/2))^2)+cos({lat1*π}/180)*cos({lat2*π}/180)*(sin(dlong/2))^2=0.0151
Best regards,
Mike Kaganski
Users browsing this topic
Guest
2 Pages12>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.