Ask Your Question

Any way to define variables as constant?

asked 2010-11-17 05:39:32 -0600

Shu gravatar image

updated 2010-11-17 06:38:35 -0600

I want to come up with a function that will return true when I compare $(x-1)^2+C$ and $x^2-2x+C$ where $C$ is an arbitrary constant. Any way that you know can do this ?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2010-11-17 07:04:42 -0600

So you want to know if a specific mathematical expression (like $(x-1)^2 - (x^2-2x))$ is a constant. Just check whether its derivative is zero:

sage: var('C, C2')
sage: diff(((x-1)^2+C) - (x^2-2*x+C2), x)
sage: bool(diff(((x-1)^2+C) - (x^2-2*x+C2), x) == 0)
edit flag offensive delete link more

answered 2010-11-17 06:00:13 -0600

There is no such function, because they're not equal. Perhaps the second expression should be x^2-2x+1+C...

What have you tried? Here are two options:

sage: var('C')
sage: expand(((x-1)^2+C) - (x^2-2*x+1+C))
sage: bool(expand((x-1)^2+C) == expand(x^2-2*x+1+C))
edit flag offensive delete link more

answered 2010-11-17 06:18:06 -0600

Shu gravatar image

updated 2010-11-17 06:39:50 -0600

I know there is none. But I want to make one if possible at all. Probably you will like the expression with different "C"

$(x-1)^2+C_1$ and $x^2-2x+C_2$

For any value of $C_1$ there is a value of $C_2$ that makes the two equations equal. Anyone else have any idea?

edit flag offensive delete link more


one can find indefinite integral of sin(x)cos(x) as (1/2)*(sin(x))^2+C_1 or -(1/2)*(cos(x))^2+C_2 both are right. But can I make a function using sage methods that will consider both as same?

Shu gravatar imageShu ( 2010-11-17 06:20:55 -0600 )edit

hey you can put math between dollar signs and it'll typeset

Evgeny gravatar imageEvgeny ( 2010-11-17 06:22:49 -0600 )edit

will do next time. thanks for letting me know.

Shu gravatar imageShu ( 2010-11-17 06:26:36 -0600 )edit

you can edit your previous posts too :)

Evgeny gravatar imageEvgeny ( 2010-11-17 06:30:12 -0600 )edit

I was able to edit the answer, but do not see any edit button for comments.

Shu gravatar imageShu ( 2010-11-17 06:41:33 -0600 )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


Asked: 2010-11-17 05:39:32 -0600

Seen: 2,119 times

Last updated: Nov 17 '10