Post Reply 
Integration in Python
05-08-2021, 04:07 PM
Post: #1
Integration in Python
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;
Find all posts by this user
Quote this message in a reply
05-08-2021, 04:45 PM
Post: #2
RE: Integration in Python
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;
Find all posts by this user
Quote this message in a reply
05-08-2021, 05:34 PM
Post: #3
RE: Integration in Python
(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)'
Find all posts by this user
Quote this message in a reply
05-08-2021, 07:16 PM
Post: #4
RE: Integration in Python
it works! Thanks so much! Another question: the result appears in the "Terminal" screen: how can I get the result in the "CAS" screen?
Find all posts by this user
Quote this message in a reply
05-08-2021, 07:42 PM
Post: #5
RE: Integration in Python
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)