HP Forums
Integration in Python - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Integration in Python (/thread-16898.html)



Integration in Python - robmio - 05-08-2021 04:07 PM

Hello, how can i insert an integral in python? For example:
Code:

#PYTHON EXPORT integrale
import sys
from hpprime import *
from math import *
xx=float(sys.argv[0])
yy=float(sys.argv[1])
                              gg=∫(x,x,xx,yy)
print(gg)
eval("wait(0)")
#end
 
EXPORT Prove(a,b)
BEGIN
 PYTHON(integrale,a,b);
END;



RE: Integration in Python - robmio - 05-08-2021 04:45 PM

In reality, the calculation of the integral, with extremes equal to "xx = 0" and "yy = 3", instead of being equal to 9/2, becomes equal to "yy^2/2 - xx^2/2". How can I express, in the integral, the values given to "xx" and "yy"?

Code:

#PYTHON EXPORT integrale
import sys
from hpprime import *
from cas import *
xx=sys.argv[0]
yy=sys.argv[1]
xx=float(xx)
yy=float(yy)
gg=caseval("int(x,x,xx,yy)")
print(gg)
#end
 
EXPORT Prova(a,b)
BEGIN
 PYTHON(integrale,a,b);
END;



RE: Integration in Python - Albert Chan - 05-08-2021 05:34 PM

(05-08-2021 04:45 PM)robmio Wrote:  gg=caseval("int(x,x,xx,yy)")

You need to interpolate the string

>>> xx, yy = "0", "3"
>>> "int(x, x, {0}, {1})".format(xx,yy)
'int(x, x, 0, 3)'


RE: Integration in Python - robmio - 05-08-2021 07:16 PM

it works! Thanks so much! Another question: the result appears in the "Terminal" screen: how can I get the result in the "CAS" screen?


RE: Integration in Python - robmio - 05-08-2021 07:42 PM

Also, why is it an error if I set the extremes "xx = 0" and "yy = 1000"? In fact, if I set the upper extreme to "999", the result is right.