Ask Your Question

Simplify, Solve Equation and use solution

asked 2011-01-28 10:07:13 +0200

manifold gravatar image

updated 2011-01-28 10:18:02 +0200

DSM gravatar image

Hi, I'm new to sage, and have the following question: I have the following code:

x,y=var('x y')

f(x,y)= sin(x)*cos(y)+sin(y)*cos(x)


Sage obiously doesn't simplify the function f... (simple trigonometric expression). And it doesn't solve it.

1) How can I simplify the function?

2) How can I use the result? For example: I have as an result: solution=[x == -1] How can I replace this x in an other function (example: sin(x)). In mathematica I would do: sin(x) /. solution or manually: sin(x) /. x->(-1)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-01-28 10:33:45 +0200

kcrisman gravatar image

A few comments.

  • If you use the f(x,y) syntax, you don't have to declare the variables ahead of time.
  • Using results is not too bad, because you can ask for them as a dictionary. There are other examples in the doc, I think, but for example:

    sage: B = (x^2-1).solve(x)

    sage: G = x^3+3*x

    sage: [G.subs(b) for b in B]

    [-4, 4]

    sage: B = (x^2-1).solve(x,solution_dict=True)

    sage: [G.subs(b) for b in B]

    [-4, 4]

  • The actual first question is hard to find, and maybe should be part of our full simplification...:

sage: f(x,y)=sin(x)cos(y)+sin(y)cos(x)

sage: f.trig_reduce()

(x, y) |--> sin(x + y)

Note to Evgeny: I cannot get code formatted text after a bullet point. What gives? I asked this on the askbot website too.

edit flag offensive delete link more


Beat me by three minutes. :^)

DSM gravatar imageDSM ( 2011-01-28 10:37:57 +0200 )edit

answered 2011-01-28 10:59:18 +0200

manifold gravatar image

updated 2011-01-28 11:07:17 +0200

Thanks it works!

Here for everyone the code to show it:

# Solve an equation an use the solution 

G = x^3-i


[G.subs(j) for j in mysol]

But the trig reduce doesn't work with this code:

f(x,y)= sin(x)*cos(y)+sin(y)*cos(x)


I still get (x, y) |--> sin(x)cos(y) + sin(y)cos(x)

edit flag offensive delete link more


f.trig_reduce() returns a *copy* of f which has been trig_reduced. It doesn't affect f. Try f=f.trig_reduce().

DSM gravatar imageDSM ( 2011-01-28 11:17:09 +0200 )edit

thanks! it works.

manifold gravatar imagemanifold ( 2011-01-28 11:27:49 +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: 2011-01-28 10:07:13 +0200

Seen: 16,685 times

Last updated: Jan 28 '11