mathematical calculation
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller
mathematical calculation
Is there a function that performs more complex mathematical calculations in LiveCode?
I tried to calculate a probability following log normal distribution or Gamma distribution, but I couldn't do it with simple function.
I also wish there are some APIs or functions to calculate integral functions.
If anyone who knows well the mathematical expressions in LiveCode, please help me.
I tried to calculate a probability following log normal distribution or Gamma distribution, but I couldn't do it with simple function.
I also wish there are some APIs or functions to calculate integral functions.
If anyone who knows well the mathematical expressions in LiveCode, please help me.
Re: mathematical calculation
Hello yochankim,
welcome to the forum!
I'll move this to the "Talking Livecode" forum, since this is defintively no "Announcement".
Best
Klaus
welcome to the forum!
I'll move this to the "Talking Livecode" forum, since this is defintively no "Announcement".
Best
Klaus

 Livecode Opensource Backer
 Posts: 5071
 Joined: Fri Feb 19, 2010 10:17 am
 Location: Bulgaria
Re: mathematical calculation
I must be a bit slow, but I don't really understand this because, as far as I know one sets up a functiona function that performs more complex mathematical calculations
to perform a specific mathematical calculation; there is no 'function' that performs mathematical
calculations as such.
For instance (and my example is not complex), if I want a list of the first 10 cube numbers I might
make this sort of thing:
and then call the function from somewherefunction KAABA
for X=1 to 10
put (X^3) into line X of field "fOUTPUT"
next X
end KAABA
although, frankly I'd not bother putting that inside a function with a name;
I'd just put it inside a "on mouseUp" statement in a button.

 VIP Livecode Opensource Backer
 Posts: 7177
 Joined: Wed May 06, 2009 2:28 pm
 Location: New York, NY
Re: mathematical calculation
@Richmond.
Your handler is pseudopseudoCode?
@ yochankim
Anyway, there are several builtin functions that perform more complex mathematical tasks than, say, "add".
But there are no function that, as you mentioned, will integrate even a function such as "x^2 dx". This sort of thing has to built with explicit code.
What specifically did you have in mind?
Craig Newman
Your handler is pseudopseudoCode?
Code: Select all
on mouseUp
repeat with y = 1 to 10
put y ^ 3 into line y of fld "output"
end repeat
end mouseUp
Anyway, there are several builtin functions that perform more complex mathematical tasks than, say, "add".
But there are no function that, as you mentioned, will integrate even a function such as "x^2 dx". This sort of thing has to built with explicit code.
What specifically did you have in mind?
Craig Newman
Last edited by dunbarx on Tue Mar 05, 2019 6:21 pm, edited 1 time in total.

 VIP Livecode Opensource Backer
 Posts: 2262
 Joined: Thu Feb 28, 2013 11:52 pm
 Location: Göttingen, DE
Re: mathematical calculation
There is no integration method implemented in LiveCode, so normal, lognormal or gamma distributions are not "directly" doable in LC Script.
Implementing integration by some method for that would be much too slow with LC Script.
But there is a fine javaScript library that is very fast and accessible via a browser widget.
[I'll publish a statisticalmethodsstack to that until the end of next week (is already 70% done).]
Implementing integration by some method for that would be much too slow with LC Script.
But there is a fine javaScript library that is very fast and accessible via a browser widget.
[I'll publish a statisticalmethodsstack to that until the end of next week (is already 70% done).]
shiftLock happens

 Livecode Opensource Backer
 Posts: 5071
 Joined: Fri Feb 19, 2010 10:17 am
 Location: Bulgaria
Re: mathematical calculation
No: it's not: it is a bad case of my mixing up BBC BASIC with LiveCode.Your handler is pseudopseudCode?
 
Just thinking about the possibility makes me excited.

 Livecode Opensource Backer
 Posts: 5071
 Joined: Fri Feb 19, 2010 10:17 am
 Location: Bulgaria
Re: mathematical calculation
No, I don't suppose you can.I tried to calculate a probability following log normal distribution or Gamma distribution, but I couldn't do it with simple function.
If you are trying to do this sort of calculation I don't think should hold you back in any way,
so my feeling is that you have to sit down with a pencil and paper and work out a number of
algorhithms that can do this sort of calculation AND then implement them in LiveCode.
If you are looking for readymade stuff in LiveCode that will do your work for you, you
will be disappointed: but that is because LiveCode is a programming suite and not a
prepackaged Mathematics application such as Wolfram Mathematica:
https://www.wolfram.com/mathematica/?source=nav
If you are looking for people who will do your Mathematics for you on the LiveCode Forums
you will also be disappointed.
If you are looking for help in the general direction of developing algorhithms to solve
Maths problems you should find it on the Forums and here:
http://livecode1001.blogspot.com/search ... Statistics
http://livecode1001.blogspot.com/search ... athematics

 VIP Livecode Opensource Backer
 Posts: 7177
 Joined: Wed May 06, 2009 2:28 pm
 Location: New York, NY
Re: mathematical calculation
Just for fun, and to see if I remember just a little calculus and also to not work at my job for a little while, this function will integrate an algebraic expression in a field 1 and put the result into a fld 2:
It is purely bruteforce, and, er, somewhat limited in scope.
But this is what you would have to do to create a library of math functions.
Craig
Code: Select all
on mouseup
put integrate(fld 1,"x") into fld 2
end mouseup
function integrate arg,var
set the itemDel to var
put item 1 of arg into coeff
if coeff = 0 or coeff = 1 then put "" into coeff
put item 2 of arg into everythingElse
if everythingElse contains "^" then
set the itemDel to "^"
put word 1 of item 2 of everythingElse into expon
put word 2 of everythingElse into operator
put word 3 of everythingElse into const
else
put 1 into expon
put word 1 of everythingElse into operator
put word 2 of everythingElse into const
end if
add 1 to expon
multiply coeff by expon
if coeff = 0 then put "" into coeff
return coeff & var & "^" & expon && "/" && expon && operator && const & var && "C"
end integrate
But this is what you would have to do to create a library of math functions.
Craig
Re: mathematical calculation
Thank you,richmond62!
You showed me the reality of LiveCode and its potential also.
Anyway can I get the source code of the statistical program in the "livecode1001...Statistics" site?
You showed me the reality of LiveCode and its potential also.
Anyway can I get the source code of the statistical program in the "livecode1001...Statistics" site?
richmond62 wrote: ↑Tue Mar 05, 2019 6:32 pm
If you are looking for help in the general direction of developing algorhithms to solve
Maths problems you should find it on the Forums and here:
Re: mathematical calculation
Craig,
Thank you for sharing your idea of integration. That was what I looking for.
If you don't mind, can I know how can I describe a mathematical expression in field 1?
Just showing an example is enough to understand your function.
Thank you so much.
Thank you for sharing your idea of integration. That was what I looking for.
If you don't mind, can I know how can I describe a mathematical expression in field 1?
Just showing an example is enough to understand your function.
Thank you so much.
dunbarx wrote: ↑Tue Mar 05, 2019 9:53 pmJust for fun, and to see if I remember just a little calculus and also to not work at my job for a little while, this function will integrate an algebraic expression in a field 1 and put the result into a fld 2:It is purely bruteforce, and, er, somewhat limited in scope.Code: Select all
on mouseup put integrate(fld 1,"x") into fld 2 end mouseup function integrate arg,var set the itemDel to var put item 1 of arg into coeff if coeff = 0 or coeff = 1 then put "" into coeff put item 2 of arg into everythingElse if everythingElse contains "^" then set the itemDel to "^" put word 1 of item 2 of everythingElse into expon put word 2 of everythingElse into operator put word 3 of everythingElse into const else put 1 into expon put word 1 of everythingElse into operator put word 2 of everythingElse into const end if add 1 to expon multiply coeff by expon if coeff = 0 then put "" into coeff return coeff & var & "^" & expon && "/" && expon && operator && const & var && "C" end integrate
But this is what you would have to do to create a library of math functions.
Craig
Re: mathematical calculation
I will look forward your product. Thank you for the valuable comment!
[hh] wrote: ↑Tue Mar 05, 2019 3:25 pmThere is no integration method implemented in LiveCode, so normal, lognormal or gamma distributions are not "directly" doable in LC Script.
Implementing integration by some method for that would be much too slow with LC Script.
But there is a fine javaScript library that is very fast and accessible via a browser widget.
[I'll publish a statisticalmethodsstack to that until the end of next week (is already 70% done).]
Re: mathematical calculation
@Craig
Thank you for your answer. I am just looking the integration function, but, I have to develop it by myself as you write.
If somebody develop a library supporting the mathematical function, I will buy it!
But, unfortunately, I will develop the code for my personal purpose.
Anyway, thank you Craig!
Thank you for your answer. I am just looking the integration function, but, I have to develop it by myself as you write.
If somebody develop a library supporting the mathematical function, I will buy it!
But, unfortunately, I will develop the code for my personal purpose.
Anyway, thank you Craig!
dunbarx wrote: ↑Tue Mar 05, 2019 3:14 pm@Richmond.
Your handler is pseudopseudoCode?
@ yochankimCode: Select all
on mouseUp repeat with y = 1 to 10 put y ^ 3 into line y of fld "output" end repeat end mouseUp
Anyway, there are several builtin functions that perform more complex mathematical tasks than, say, "add".
But there are no function that, as you mentioned, will integrate even a function such as "x^2 dx". This sort of thing has to built with explicit code.
What specifically did you have in mind?
Craig Newman
Re: mathematical calculation
@richmond62
Thank you for your comment.
I am trying to develop a function for my program.
Thank you for your comment.
I am trying to develop a function for my program.
richmond62 wrote: ↑Tue Mar 05, 2019 2:41 pmI must be a bit slow, but I don't really understand this because, as far as I know one sets up a functiona function that performs more complex mathematical calculations
to perform a specific mathematical calculation; there is no 'function' that performs mathematical
calculations as such.
For instance (and my example is not complex), if I want a list of the first 10 cube numbers I might
make this sort of thing:
and then call the function from somewherefunction KAABA
for X=1 to 10
put (X^3) into line X of field "fOUTPUT"
next X
end KAABA
although, frankly I'd not bother putting that inside a function with a name;
I'd just put it inside a "on mouseUp" statement in a button.
Re: mathematical calculation
Dear Klaus,
Thank you for your management!
I am not familiar with any kind of forum websites. I am sorry for that.
Next time, I will post my opinions or questions on the right place.
Thank you!!
Thank you for your management!
I am not familiar with any kind of forum websites. I am sorry for that.
Next time, I will post my opinions or questions on the right place.
Thank you!!
Re: mathematical calculation
I have stack that I uploaded to LiveCode Sample Stack called Coup de Graph. It may give you some ideas.
Cheers,
Roger
Cheers,
Roger