Ask Your Question
0

Choosing the way a function is displayed

asked 2020-04-23 12:12:23 +0100

Cyrille gravatar image

1) I have the following function z=-(D*p-p*x - D + w0)/ (p-1). Is it possible to display it as -(p/(1-p))*x + ((w0-D*(1-p)))/(1-p)? 2) Can I select a part a this function --- the factor of x, x and the last part ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-04-23 12:29:11 +0100

rburing gravatar image

updated 2020-04-23 12:35:16 +0100

Yes. I guess you have it as a symbolic expression, like this:

sage: var('p,x,D,w0')
sage: z = -(D*p-p*x - D + w0)/(p-1)

You can consider it as an element of the ring $\mathbb{Q}(p,D,w_0)[x]$, and then get the coefficients:

sage: A = PolynomialRing(QQ, names='p,D,w0').fraction_field()
sage: B = PolynomialRing(A, names='x')
sage: f = B(z); f
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: f.coefficients()
[(-p*D + D - w0)/(p - 1), p/(p - 1)]
sage: f.monomial_coefficient(B(x))
p/(p - 1)
sage: f.monomial_coefficient(B(1))
(-p*D + D - w0)/(p - 1)

You might want to convert these back to symbolic expressions again:

sage: SR(f.monomial_coefficient(B(x)))
p/(p - 1)
sage: SR(f.monomial_coefficient(B(1)))
-(D*p - D + w0)/(p - 1)

Or avoid symbolic expressions entirely, by defining z as a polynomial directly:

sage: A.<p,D,w0> = PolynomialRing(QQ)
sage: B.<x> = PolynomialRing(A.fraction_field())
sage: z = -(D*p-p*x - D + w0)/(p-1); z
(p/(p - 1))*x + (-p*D + D - w0)/(p - 1)
sage: z.monomial_coefficient(x)
p/(p - 1)

etc.

edit flag offensive delete link more

Comments

Thanks to your nice answer. I wonder if working in QQ ring, could forbid me to works after on reals ?

Cyrille gravatar imageCyrille ( 2020-04-23 12:43:35 +0100 )edit

Yes, if you need irrational coefficients you should change QQ to something else. If the coefficients are numerical real or complex you could use e.g. RDF or CDF. If the coefficients are algebraic numbers then you could use e.g. QQbar or a NumberField. You could also replace an irrational by an extra variable in A and do the substitution later.

rburing gravatar imagerburing ( 2020-04-23 12:49:45 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-23 12:12:23 +0100

Seen: 211 times

Last updated: Apr 23 '20