Variable assignment bug

Variable assignment bug - Сообщения

#1 Опубликовано: 17.03.2010 10:34:28
dardard

dardard

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

Группа: User

First, I want to thank you for all the excellent job done.
But anyway, I have found an annoying thing when playing with units.
The problem appear in either beta versions of Smath.

I don't know how to put images on topics, so :
try this
temp1:=150°C
temp2:=45°C

temp3:=0,8.temp1
result temp3=65,37°C (instead of 120°C)

temp4:=temp1-temp2
result temp4=-168,15°C (instead of 105°C)

The results are good if I do not use the units.
Maybe I am not doing things in the right way.

Regards
#2 Опубликовано: 17.03.2010 12:25:51
Andrey Ivashov

Andrey Ivashov

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

Группа: Super Administrator

Hello.

Thank you, dardard. Can't check it now, but will do in the evening and will inform you what is going on here.

Btw, I see you from France... can I ask you to help us to update French translation? If you have a time I can send a file with all non-translated text to you. Thanks in advance.

Best regards, Andrey Ivashov.
#3 Опубликовано: 17.03.2010 13:00:43
dardard

dardard

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

Группа: User

Feel free to send me the file for translation.
I will do my best on it. It's my pleasure if I could help the project.

Best regards
#4 Опубликовано: 17.03.2010 13:40:24
Andrey Ivashov

Andrey Ivashov

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

Группа: Super Administrator

Thank you! I've sent the file to you through Private Messages.
#5 Опубликовано: 17.03.2010 13:47:43
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,
Wrote

First, I want to thank you for all the excellent job done.
But anyway, I have found an annoying thing when playing with units.
The problem appear in either beta versions of Smath.

I don't know how to put images on topics, so :
try this
temp1:=150°C
temp2:=45°C

temp3:=0,8.temp1
result temp3=65,37°C (instead of 120°C)

temp4:=temp1-temp2
result temp4=-168,15°C (instead of 105°C)

The results are good if I do not use the units.
Maybe I am not doing things in the right way.


You should not use relative temperature scales in arithmetic operations. It is wrong.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#6 Опубликовано: 17.03.2010 15:09:24
maweilian

maweilian

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

Группа: User

Wrote

You should not use relative temperature scales in arithmetic operations. It is wrong.



Just to further explain what Radovan means here.

To perform arithmetic operations with Celsius temperatures, the temperature values must first be converted to Kelvins, the arithmetic operations performed, and then the results can be converted back to degrees Celsius. Thus,

temp1 = 150 degrees C = 423.15 K
temp2 = 105 degrees C = 318.15 K

0.8*temp1 = 0.8*423.15 K = 338.52 K = 65.37 degrees C

temp1 - temp2 = 423.15 K - 318.15 K = 105 K = -168.15 degrees C

So, anyway. There is no problem with the results provided by the software. The relative temperatures are being converted to absolute temperatures and back again behind the scenes.
Will Massie Mechanical Engineer Oregon, USA
#7 Опубликовано: 17.03.2010 15:44:46
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Sorry dardard, I should have explained this as Will did.

Thanks Will

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Опубликовано: 17.03.2010 16:43:01
dardard

dardard

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

Группа: User

Thank you for the explanations.
I have made a try with the use of Kelvin values and it works well.
The only drawback is when you have formulas with multiplication/division the parameters must be adjusted.
For instance, my example of temp1*0,8 en celsius is not equal in kelvin so the 0,8 must be changed to 0,9338.
This is because 150°*0,8+273,15 is not equal to (150+273,15)*0,8.

I don't know how to handle this in the easy way.

Regards,
#9 Опубликовано: 18.03.2010 10:23:46
Greg Locock

Greg Locock

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

Группа: User

There is no physically valid equation that uses something like 0.8*21 deg C. In engineering if you need to do sums like that you need to use absolute temperatures (Rankin or Kelvin).

#10 Опубликовано: 18.03.2010 16:01:51
maweilian

maweilian

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

Группа: User

Wrote

There is no physically valid equation that uses something like 0.8*21 deg C. In engineering if you need to do sums like that you need to use absolute temperatures (Rankin or Kelvin).



What Greg says is most certainly true. In engineering and scientific applications, absolute temperatures must be used. Any relative temperature must first be converted before being plugged into any formulas.

However, the results provided by the software for the difference of temperatures,

Wrote

temp1 - temp2 = 423.15 K - 318.15 K = 105 K = -168.15 degrees C



is surely incorrect when viewed from a different perspective. Since the operation involves finding the difference in two temperatures, the result is no longer absolute. And since a difference of one Kelvin is equal to a difference of one Celsius degree, it would be equally correct to say:

temp1 - temp2 = 150 degrees C - 45 degrees C = 105 degrees C
OR
temp1 - temp2 = 423.15 K - 318.15 K = 105 K

So, when finding the difference in temperatures, the software actually is giving a faulty answer in giving the following results:

temp1:=150 deg C
temp2:=45 deg C
temp1-temp2=-168.15 deg C

Thus, showing that my previous, much-too-broad statement about there being no problem with the results, may very well be incorrect .
Will Massie Mechanical Engineer Oregon, USA
#11 Опубликовано: 18.03.2010 16:50:28
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello Will,

Do not worry about this. I do not have here the recent version of SMath but try this:

dC:=1*K //1degC = 1K

temp1:=150*degC
diffT1:=temp1 - 20*dC
diffT1 =
diffT2:=temp1 + 30*dC
diffT2 =
(-50)*degC + 20*dC =
(-50)*degC - 20*dC =

and reperesent teh results in degC.

I tried this and I think the results would all be Ok. The same should be with degF and R.

Your example is not correct:
temp1 - temp2 = 150 degrees C - 45 degrees C = 105 degrees C
it should be:
temp1 - temp2 = 150 degrees C - 45 degrees C = 105 dC

This should be wrong:

temp1:=50*degC
temp2:=20*degC
temp1:=temp1+temp2

Regards,
Radovan

PS. Will, please check it out
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#12 Опубликовано: 19.03.2010 11:36:39
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Here are few hints related to temperature scales and expression with inconsistent units:



Regards,
Radovan

PS. Pay attention. When the color of the region with units variable (default blue) or text variable (default red) has been changed, then you can not get the colors back. See the example above with grades Celsius (units are in black color, and you can not make them blue anymore). At least, I think there is no way of doing that yet.
Also, if you change the default text color (black), then everything will be in that color. There will be no difference in text, math and units.
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#13 Опубликовано: 19.03.2010 12:12:52
Andrey Ivashov

Andrey Ivashov

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

Группа: Super Administrator

Wrote

When the color of the region with units variable (default blue) or text variable (default red) has been changed, then you can not get the colors back.


Thank you. Reproduced. Will fix.
#14 Опубликовано: 19.03.2010 15:32:27
maweilian

maweilian

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

Группа: User

Wrote

Hello Will,

Do not worry about this. I do not have here the recent version of SMath but try this:

dC:=1*K //1degC = 1K

temp1:=150*degC
diffT1:=temp1 - 20*dC
diffT1 =
diffT2:=temp1 + 30*dC
diffT2 =
(-50)*degC + 20*dC =
(-50)*degC - 20*dC =

and reperesent teh results in degC.

I tried this and I think the results would all be Ok. The same should be with degF and R.

Your example is not correct:
temp1 - temp2 = 150 degrees C - 45 degrees C = 105 degrees C
it should be:
temp1 - temp2 = 150 degrees C - 45 degrees C = 105 dC

This should be wrong:

temp1:=50*degC
temp2:=20*degC
temp1:=temp1+temp2

Regards,
Radovan

PS. Will, please check it out




Radovan,

Thanks for the response above. Your solution (representing the difference of temperatures as deltaC and defining that as a unit) is a good answer to the difficulty I mentioned previously. For the benefit of all, I will include a screenshot of my attempt to test the first part of what you showed above in Smath:


However, when I tested the next expressions in your example above I came across some unusual results:

The answers are incorrect AND the answers are in negative Kelvins, which is impossible. I think that an error should be produced before displaying a negative answer with absolute temperature units.

The answer is incorrect because Smath is not processing the Celsius temperature a -50 degC, but as -(50 degC). So the 50 degC is converted to Kelvins and then the negative sign is applied. I cannot figure out how to correct this problem. See below:


Will Massie Mechanical Engineer Oregon, USA
#15 Опубликовано: 19.03.2010 16:14:36
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello Will,

This will certanly be beneficial for other users, thank you.

The negative Celsius and Fahrenheight should be inserted as negative values inside parantheses multiplied by temperture unit

(-50)*degC
or
(-50)*degF

Multiplication here must be inserted. I think you forgot to do that. It seems that everything else, as you tested, should be incorect.
I am sorry, I've tryed this few days ago and it was Ok, but forgot again to double check this at my office.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#16 Опубликовано: 19.03.2010 16:58:33
maweilian

maweilian

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

Группа: User

Wrote

Hello Will,

This will certanly be beneficial for other users, thank you.

The negative Celsius and Fahrenheight should be inserted as negative values inside parantheses multiplied by temperture unit

(-50)*degC
or
(-50)*degF

Multiplication here must be inserted. I think you forgot to do that. It seems that everything else, as you tested, should be incorect.
I am sorry, I've tryed this few days ago and it was Ok, but forgot again to double check this at my office.

Regards,
Radovan




Thanks again for the response. Multiplying the value in parentheses by the unit does fix the problem.

However, I think that this workaround, although acceptable, is not the best solution. The engineering calculator I use actually has a special key for inserting a "negative sign" and a separate key for inserting a "subtraction operator". When displayed on the screen, the "negative sign" appears slightly shorter and is quite close to the number to which it belongs, and the "subtraction operator" is longer and is separated by a space from the numbers on either side of it. This solution would look much nicer and cleaner on the screen or printed on paper versus having to use parentheses and a multiplication operator (it also would reduce the number of keystrokes).

Also, I think that negative values with absolute temperature units should not be allowed.

Just my opinion.
Will Massie Mechanical Engineer Oregon, USA
#17 Опубликовано: 19.03.2010 17:54:50
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Yes Will, I understand your point (I mean on relative and apsolute temperature scales). This way the results which include units remaine to the user to conclude if they are correct or not. It is working this way and do not know if something could be done in order to make it better.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#18 Опубликовано: 19.03.2010 23:32:07
Greg Locock

Greg Locock

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

Группа: User

Negative temperature differences are valid, for example if you are summing a radiation absorption problem, so it isn't quite as simple as saying that negative results are invalid.
#19 Опубликовано: 22.03.2010 16:56:35
maweilian

maweilian

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

Группа: User

Wrote

Negative temperature differences are valid, for example if you are summing a radiation absorption problem, so it isn't quite as simple as saying that negative results are invalid.



Greg,

This is true. Good point. I withdraw my statement regarding the invalidity of a negative result for absolute temperature values.

But, I still stand by my previous comments regarding the usefulness of a solution to distinguish between a "negative sign" and a "subtraction operator".
Will Massie Mechanical Engineer Oregon, USA
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений