Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any possibility of using "chaospy.poly.base.Poly" object as python symbolic expression #48

Closed
cc636489 opened this issue May 31, 2017 · 4 comments

Comments

@cc636489
Copy link

Hi, Jonathan,

First, thank you for this nice package, it's light and helpful! I am currently exploring it with fun!

My question is about using "chaospy.poly.base.Poly" object as python symbolic expression. Is that possible? Since we can do the following:

print orthpol[3]
q1^2-2.0q1+0.986666666667

I can change the result to a string by doing str(orthpol[3]), which is convenient for further symbolic integration. However, the expression presented above is not a valid python expression. So is there any possibility that I can make use of the orthogonalized polynomials freely generated by chaospy? and how?

Thank you in advance for your time and consideration!

Cheers,
Chen

@jonathf
Copy link
Owner

jonathf commented May 31, 2017

Interesting usecase. I have support for this unexposed in the API, and it isn't complicated to expose it to accommodate your need. I just pushed a commit to the development branch allowing for the following:

import chaospy as cp

cp.poly.base.POWER = "**"
cp.poly.base.SEP = "*"

q0 = cp.variable()
orth = q0**2-2.*q0+0.98666666666666
print(eval(str(orth)))
# q0**2-2.0*q0+0.986666666667

@jonathf
Copy link
Owner

jonathf commented May 31, 2017

Also note, if the plan is to parse the coefficients or extract components, there are functions for that too:

print(cp.decompose(orth))
# [0.986666666667, -2.0*q0, q0**2]
print(orth.coeffs())
# [ 0.98666667 -2.          1.        ]

@cc636489
Copy link
Author

cc636489 commented May 31, 2017 via email

@jonathf
Copy link
Owner

jonathf commented Jun 7, 2017

I consider this issue as solved. Feel free to reopen if you feel this is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants