1 страниц (9 вхождений)
Molar mass calculation - Сообщения
#1 Опубликовано: 02.10.2010 14:51:22
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).
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 Опубликовано: 02.10.2010 15:58:55
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.
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 Опубликовано: 02.10.2010 16:09:44
Hello oldhand,
You might consider some simpler calculation in the meantime, of course.

Regards,
Radovan
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 Опубликовано: 02.10.2010 16:17:21
Hello Andrey,
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
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 Опубликовано: 02.10.2010 16:23:37
Hello Radovan. Thanks for pointing this out but what do you think should be the answer of "hello">"world"=?
Regards.
Regards.
#6 Опубликовано: 02.10.2010 16:32:11
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"
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 Опубликовано: 03.10.2010 14:34:12
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?
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 Опубликовано: 03.10.2010 15:05:18
Hello.
Maybe this will help you:

(download source)
Note that this is only possible within SMath Studio 0.89.8 beta released today.
Regards.
Maybe this will help you:
(download source)
Note that this is only possible within SMath Studio 0.89.8 beta released today.
Regards.
#9 Опубликовано: 03.10.2010 22:29:44
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.
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.
1 страниц (9 вхождений)
-
Новые сообщения
-
Нет новых сообщений