Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline oldhand  
#1 Posted : 02 October 2010 21:51:22(UTC)
oldhand

Rank: Newbie

Groups: Registered
Joined: 02/10/2010(UTC)
Posts: 3

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).


Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Andrey Ivashov  
#2 Posted : 02 October 2010 22:58:55(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
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.

Edited by user 02 October 2010 23:13:01(UTC)  | Reason: Not specified

Offline omorr  
#3 Posted : 02 October 2010 23:09:44(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
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!"
Offline omorr  
#4 Posted : 02 October 2010 23:17:21(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello Andrey,
smath 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!"
Offline Andrey Ivashov  
#5 Posted : 02 October 2010 23:23:37(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Hello Radovan. Thanks for pointing this out but what do you think should be the answer of "hello">"world"=?

Regards.
Offline omorr  
#6 Posted : 02 October 2010 23:32:11(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
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"

Edited by user 03 October 2010 09:22:35(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline oldhand  
#7 Posted : 03 October 2010 21:34:12(UTC)
oldhand

Rank: Newbie

Groups: Registered
Joined: 02/10/2010(UTC)
Posts: 3

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?
Offline Andrey Ivashov  
#8 Posted : 03 October 2010 22:05:18(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Hello.

Maybe this will help you:

(download source)

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

Regards.
Offline oldhand  
#9 Posted : 04 October 2010 05:29:44(UTC)
oldhand

Rank: Newbie

Groups: Registered
Joined: 02/10/2010(UTC)
Posts: 3

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.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.