# Define a factor of an equation

asked 2015-10-23 03:50:36 +0200

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I have the following code :

p, t= var('p t')
a=(-2*p*t^2-p^2*t)+(2*t*p-p^2)+t+1
b=(p*t^2+2*p^2*t)+(2*t*p-t^2)-p+1
c=(p*t^2-p^2*t)+(t^2+2*t*p+p^2)+t-p  #3 sides (a,b,c) in terms of theta and phi [equation (1.1)]
s=factor(2*c^2+2*a^2-b^2);s


which yields

(3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1)^2


I want to use the factor (3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1) in my next command. How should I define that. Like I want to set m = 3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1. Tried using operand() but did not help much

edit retag close merge delete

Sort by ยป oldest newest most voted

Is that what you want

sage: s = factor(2*c^2+2*a^2-b^2)
sage: s.operands()
[3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1, 2]
sage: m = s.operands()[0]
sage: m
3*p*t^2 - 2*p^2 - 2*p*t + t^2 + p + 2*t + 1

more

Thank you @vdelecroix !! This worked for me. Earlier i did not include [0]

( 2015-10-23 04:14:00 +0200 )edit
1

The brackets [0] are used to access items of a list. If you want to use the power you can do

sage: s.operands()[1]
2

( 2015-10-23 04:16:20 +0200 )edit