Page 2 of 2

Re: mathematical calculation

Posted: Wed Mar 06, 2019 12:30 pm
by yochankim
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

Re: mathematical calculation

Posted: Wed Mar 06, 2019 12:50 pm
by bogs
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!
Yay!

Re: mathematical calculation

Posted: Wed Mar 06, 2019 4:28 pm
by dunbarx
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
   
   add 1 to expon
   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

Re: mathematical calculation

Posted: Wed Mar 06, 2019 4:35 pm
by dunbarx
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

Re: mathematical calculation

Posted: Tue Mar 12, 2019 3:13 pm
by [-hh]
Statistical Distributions:
viewtopic.php?p=177558#p177558