Integration in Python
05-08-2021, 04:07 PM
Post: #1
 robmio Member Posts: 169 Joined: Jan 2020
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;
05-08-2021, 04:45 PM
Post: #2
 robmio Member Posts: 169 Joined: Jan 2020
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;
05-08-2021, 05:34 PM
Post: #3
 Albert Chan Senior Member Posts: 2,357 Joined: Jul 2018
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)'
05-08-2021, 07:16 PM
Post: #4
 robmio Member Posts: 169 Joined: Jan 2020
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?
05-08-2021, 07:42 PM
Post: #5
 robmio Member Posts: 169 Joined: Jan 2020
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.
 « Next Oldest | Next Newest »

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