Ask Your Question
1

Define a factor of an equation

asked 2015-10-22 20:50:36 -0500

this post is marked as community wiki

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-10-22 21:08:52 -0500

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
edit flag offensive delete link more

Comments

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

Sha gravatar imageSha ( 2015-10-22 21:14:00 -0500 )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
vdelecroix gravatar imagevdelecroix ( 2015-10-22 21:16:20 -0500 )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: 2015-10-22 20:50:36 -0500

Seen: 59 times

Last updated: Oct 22 '15