[SS-111][SS-2327] arguments names interference

[SS-111][SS-2327] arguments names interference - When using user functions, the answer is different than making step by step calculations. - Messages

#1 Posted: 4/22/2016 1:28:36 AM
Jose Fernando Gil

Jose Fernando Gil

0 likes in 1 posts.

Group: User

Hi, I am having some issues Here,
As my english is very bad, I prefer to show you the picture about my problem
File not found.File not found.

If I make step by step caculations, the answer is correct (Which is 19.47°). When I try to make them using user functions, the answer is wrong even if I am using the same values for parameters.
#2 Posted: 4/22/2016 2:50:11 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

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 (2 KiB) downloaded 58 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.
С уважением, Михаил Каганский
1 users liked this post
Jose Fernando Gil 4/22/2016 3:32:00 AM
#3 Posted: 4/22/2016 4:12:20 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

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
#4 Posted: 4/22/2016 10:07:43 PM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Wrote

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.
С уважением, Михаил Каганский
#5 Posted: 4/22/2016 11:37:54 PM
CBG

CBG

77 likes in 312 posts.

Group: User

MikeKaganky this right, changing the names of variables , solve the problem.


Cinematica_Inversa.png


Best Regards
#6 Posted: 4/22/2016 11:49:19 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

"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.
#7 Posted: 4/23/2016 12:07:17 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Wrote

"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:
Wrote

Your coding is not correct:


Btw, whos? A person who implemented Matlab's mwatan2? Does that belong here?
С уважением, Михаил Каганский
#8 Posted: 4/23/2016 12:29:02 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

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




#9 Posted: 4/23/2016 12:32:17 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... and by same token: mwatan2[,,] is bug in Smath 5346.
Two birds in one shot !
#10 Posted: 4/23/2016 12:50:38 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Wrote

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



Wrote

... 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.
С уважением, Михаил Каганский
#11 Posted: 4/23/2016 7:35:15 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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

#12 Posted: 4/23/2016 7:46:22 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Wrote

"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/support/knowledgecenter/SSGH4D_14.1.0/com.ibm.xlf141.aix.doc/language_ref/atan2.html?lang=en

Your version of Mathcad uses non-standard definition, but that doesn't make it standard.
С уважением, Михаил Каганский
#13 Posted: 4/23/2016 8:51:10 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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

#14 Posted: 4/23/2016 8:53:21 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Jean,
you are ignorant troll. End of it. I only ask you: please, don't ever bother to answer to my posts.
С уважением, Михаил Каганский
#15 Posted: 4/23/2016 9:06:33 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

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.

#16 Posted: 4/23/2016 10:27:19 AM
Fridel Selitsky

Fridel Selitsky

520 likes in 451 posts.

Group: User

atan2.sm (18 KiB) downloaded 49 time(s).Hi,jofegibo.

If you take the code from Wikipedia, the error will not
https://en.wikipedia.org/wiki/Atan2#Definition_and_computation

#17 Posted: 4/23/2016 10:35:25 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

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().
С уважением, Михаил Каганский
#18 Posted: 4/23/2016 2:44:38 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... all that said: "Atan(y, x) = Arg(x + yi)"

Happy reconciliation.
#19 Posted: 4/26/2016 1:08:03 AM
ur_naz

ur_naz

0 likes in 15 posts.

Group: User

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

List1.sm (10 KiB) downloaded 54 time(s).
#20 Posted: 4/26/2016 1:25:11 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Oh! You scared me!

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
С уважением, Михаил Каганский
  • New Posts New Posts
  • No New Posts No New Posts