[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. - Сообщения

#1 Опубликовано: 22.04.2016 01:28:36
Jose Fernando Gil

Jose Fernando Gil

0 сообщений из 1 понравились пользователям.

Группа: User

Hi, I am having some issues Here,
As my english is very bad, I prefer to show you the picture about my problem
Файл не найден.Файл не найден.

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 Опубликовано: 22.04.2016 02:50:11
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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 КиБ) скачан 59 раз(а).

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 пользователям понравился этот пост
Jose Fernando Gil 22.04.2016 03:32:00
#3 Опубликовано: 22.04.2016 16:12:20
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 22.04.2016 22:07:43
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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 Опубликовано: 22.04.2016 23:37:54
CBG

CBG

77 сообщений из 312 понравились пользователям.

Группа: User

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


Cinematica_Inversa.png


Best Regards
#6 Опубликовано: 22.04.2016 23:49:19
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 00:07:17
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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.

Цитата

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 Опубликовано: 23.04.2016 00:29:02
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 00:32:17
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... and by same token: mwatan2[,,] is bug in Smath 5346.
Two birds in one shot !
#10 Опубликовано: 23.04.2016 00:50:38
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 07:35:15
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 07:46:22
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 08:51:10
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 08:53:21
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: User

Jean,
you are ignorant troll. End of it. I only ask you: please, don't ever bother to answer to my posts.
С уважением, Михаил Каганский
#15 Опубликовано: 23.04.2016 09:06:33
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 10:27:19
Fridel Selitsky

Fridel Selitsky

520 сообщений из 451 понравились пользователям.

Группа: User

atan2.sm (18 КиБ) скачан 50 раз(а).Hi,jofegibo.

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

#17 Опубликовано: 23.04.2016 10:35:25
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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 Опубликовано: 23.04.2016 14:44:38
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

Happy reconciliation.
#19 Опубликовано: 26.04.2016 01:08:03
ur_naz

ur_naz

0 сообщений из 15 понравились пользователям.

Группа: User

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

List1.sm (10 КиБ) скачан 55 раз(а).
#20 Опубликовано: 26.04.2016 01:25:11
Mike Kaganski

Mike Kaganski

184 сообщений из 434 понравились пользователям.

Группа: 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
С уважением, Михаил Каганский
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений