Molar mass calculation

Molar mass calculation - Messages

#1 Posted: 10/2/2010 2:51:22 PM
oldhand

oldhand

0 likes in 3 posts.

Group: User

Andrey,

Thank you for SMath.

I am trying to write a function that would do something like

MW( "CH3OH" )= 32.04 g/mol

As I am a complete beginner, I first tried some very simple ideas:

MWH = 1.0079
MWC = 12.011
MC = 0
MH = 0
Molecule="CH3OH"
i:=1
part1=substr(Molecule,i,1)
if part1="C"
MC:=MC+MWC
else
if part1="H"
MH=MH+MWH
else
1

etc.

Please note, there is no for loop--to understand what was going on I was changing the i:=1 expression
by hand (i:=2 etc.). It took me a while to understand that "if" did not work with strings (if part1="C" is not a valid expression). I am stuck. Any pointers would be much appreciated. (And yes, I am aware of possible issues with C12H26, HCl, or Ca(OH)2).


#2 Posted: 10/2/2010 3:58:55 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Hello oldhand.

Thank you for the bug report. I've fixed comparing of strings and this will be possible in SMath Studio 0.90.

Best regards, Andrey Ivashov.
#3 Posted: 10/2/2010 4:09:44 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello oldhand,

You might consider some simpler calculation in the meantime, of course.


Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#4 Posted: 10/2/2010 4:17:21 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello Andrey,
Wrote


Thank you fo the bug report. I've fixed comparing of strings and this will be possible in SMath Studio 0.90.


I suppose there would be some logic about using all the relational operators when comparing strings besides equal to and not equal to like less then , greater then etc.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 10/2/2010 4:23:37 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Hello Radovan. Thanks for pointing this out but what do you think should be the answer of "hello">"world"=?

Regards.
#6 Posted: 10/2/2010 4:32:11 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

I do not know Andrey,

It crossed my mind that might be troublesome. Some software have the ability to compare strings based on, say, ASCII codes or something like that and to have some logic whate is "greater then" or "less then". In the case of SMath I do not have the slightest idea - many languages, fonts etc. To compare if the strings are equal or not might be useful, but do not know what to do with <,>,<=,>= .

Regards,
Radovan

EDIT:In Excel it is usual to sort cells with strings (ascending, descending)or to use IF with strings. I do not know how this realy works. I used it sometimes and connected it to the English alphabet. For instance:
IF("A"<"B";"true";"false" ) will give "true"
IF("A">"B";"true";"false" ) will give "false"
IF("A"="a";"true";"false" ) will give "true"
IF("ABC">"ABD";"true";"false" ) will give "false"
IF("hello">"world";"true";"false" ) will give "false"
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#7 Posted: 10/3/2010 2:34:12 PM
oldhand

oldhand

0 likes in 3 posts.

Group: User

Andrey,

Thanks for fixing "if" to work with strings.

Radovan: Thank you for a very simple solution. I am almost tempted to use your procedure and stop working on my MW("molecule" ) function.

I am facing another obstacle--among the string functions I couldn't find something that would give

Asc("A" ) = 65

I need this to check whether a character in "molecule" is a digit, an upper case letter, or lower case letter. Any suggestions?
#8 Posted: 10/3/2010 3:05:18 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Hello.

Maybe this will help you:

(download source)

Note that this is only possible within SMath Studio 0.89.8 beta released today.

Regards.
#9 Posted: 10/3/2010 10:29:44 PM
oldhand

oldhand

0 likes in 3 posts.

Group: User

Andrey,

Thank you very much. The two functions will definitely help. Just to understand how these things work, I tried to add a new function "IsDigit":



I think that I have now all the elements for my MW function.

Thanks again.
  • New Posts New Posts
  • No New Posts No New Posts