|
| 1 | +#------------------------------------------------------------- |
| 2 | +# This is an example of Polynomial class |
| 3 | +# The methods "derivativeTo","derivative", "copyTo" and "value" are included. |
| 4 | +#------------------------------------------------------------- |
| 5 | + |
| 6 | +import sys |
| 7 | +import math |
| 8 | + |
| 9 | +from orbit.core.orbit_utils import Polynomial |
| 10 | + |
| 11 | +poly = Polynomial(4) |
| 12 | +print ("initial order = ",poly.order()) |
| 13 | + |
| 14 | +poly.coefficient(2,2.0) |
| 15 | + |
| 16 | +print ("========Polynomial=======") |
| 17 | +order = poly.order() |
| 18 | +for i in range(order+1): |
| 19 | + print ("i=",i," coef=",poly.coefficient(i)) |
| 20 | + |
| 21 | +x = 10. |
| 22 | +y = poly.value(x) |
| 23 | +print ("x=",x," y=",y) |
| 24 | + |
| 25 | +poly1 = Polynomial() |
| 26 | +poly.derivativeTo(poly1) |
| 27 | + |
| 28 | +print ("========Derivative polynomial=======") |
| 29 | +order = poly1.order() |
| 30 | +for i in range(order+1): |
| 31 | + print ("i=",i," coef=",poly1.coefficient(i)) |
| 32 | + |
| 33 | +x = 10. |
| 34 | +y = poly1.value(x) |
| 35 | +yp = poly.derivative(x) |
| 36 | +print ("x=",x," y_prime=",y," yp =",yp) |
| 37 | + |
| 38 | +print ("========Copy of initial polynomial=======") |
| 39 | +poly2 = Polynomial() |
| 40 | +poly.copyTo(poly2) |
| 41 | +order = poly2.order() |
| 42 | +for i in range(order+1): |
| 43 | + print ("i=",i," coef=",poly2.coefficient(i)) |
| 44 | + |
| 45 | +x = 10. |
| 46 | +y = poly2.value(x) |
| 47 | +yp = poly2.derivative(x) |
| 48 | +print ("x=",x," y=",y," y_prime=",yp) |
| 49 | + |
| 50 | +""" |
| 51 | +# Memory leak test |
| 52 | +count = 1 |
| 53 | +while(1 < 2): |
| 54 | + poly1 = Polynomial() |
| 55 | + poly2 = Polynomial() |
| 56 | + poly.derivativeTo(poly1) |
| 57 | + poly.copyTo(poly2) |
| 58 | + count += 1 |
| 59 | + if(count % 100000 == 0): |
| 60 | + print ("count=",count) |
| 61 | +""" |
| 62 | + |
| 63 | +print ("Stop.") |
| 64 | +sys.exit(0) |
| 65 | + |
0 commit comments