Ask Your Question
1

Define a factor of an equation

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

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-23 04:08:52 +0200

vdelecroix gravatar image

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-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
vdelecroix gravatar imagevdelecroix ( 2015-10-23 04:16:20 +0200 )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-23 03:50:36 +0200

Seen: 213 times

Last updated: Oct 23 '15