Ask Your Question

Any way to define variables as constant?

asked 2010-11-17 12:39:32 +0200

Shu gravatar image

updated 2010-11-17 13:38:35 +0200

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 14:04:42 +0200

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 13:00:13 +0200

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 13:18:06 +0200

Shu gravatar image

updated 2010-11-17 13:39:50 +0200

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 13:20:55 +0200 )edit

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

Evgeny gravatar imageEvgeny ( 2010-11-17 13:22:49 +0200 )edit

will do next time. thanks for letting me know.

Shu gravatar imageShu ( 2010-11-17 13:26:36 +0200 )edit

you can edit your previous posts too :)

Evgeny gravatar imageEvgeny ( 2010-11-17 13:30:12 +0200 )edit

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

Shu gravatar imageShu ( 2010-11-17 13:41:33 +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


Asked: 2010-11-17 12:39:32 +0200

Seen: 2,916 times

Last updated: Nov 17 '10