mathematical calculation

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

yochankim
Posts: 8
Joined: Tue Mar 05, 2019 4:06 am

Re: mathematical calculation

Thank you!
I solve this problem with the samples!
(because my development environment is offline, I haven't seen the sample stacks. )

Best regards,
RogGuay wrote:
Wed Mar 06, 2019 6:11 am
I have stack that I uploaded to LiveCode Sample Stack called Coup de Graph. It may give you some ideas.

Cheers,
Roger

bogs
Posts: 4791
Joined: Sat Feb 25, 2017 10:45 pm

Re: mathematical calculation

RogGuay wrote:
Wed Mar 06, 2019 6:11 am
I have stack that I uploaded to LiveCode Sample Stack called Coup de Graph. It may give you some ideas.

Cheers,
Roger
Just in case yochankim is too new to know how to get to the user samples, you can either get there in the LiveCode environment from the menubar icon "User Samples" or directly through the web browser at http://livecodeshare.runrev.com/

Your sample was right at the top Roger, congrats !
Yay!

dunbarx
VIP Livecode Opensource Backer
Posts: 7154
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: mathematical calculation

First off, I updated my handler so it actually works. This does not mean it actually works.

As to your question, put something like "10x^3 + 4" into fld 1 and hit a button that contains the script below.

Code: Select all

``````on mouseup
put fld 1 into arg
put integrate(arg,"x") into fld 2
end mouseup

function integrate arg,var
set the itemDel to var
put item 1 of arg into coeff
if coeff = "" 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

if coeff ="" then return coeff & var & "^" & expon && "/" && expon && operator && const & var && "C"
else return coeff / expon & var & "^" & expon &&  operator && const & var && "C"
end integrate``````
Craig
Last edited by dunbarx on Wed Mar 06, 2019 6:18 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
Posts: 7154
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: mathematical calculation

The handler will not accommodate an expression that has the form:

"10x^3 + 3x + 5"

In other words, it does not "see" the "3x".

Can you update the function to include this extra term? It will be good practice for you in pursuit of your original inquiry.

Craig

[-hh]
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: mathematical calculation

Statistical Distributions:
viewtopic.php?p=177558#p177558
shiftLock happens