# Simplify, Solve Equation and use solution 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)
f.full_simplify
show(f(x,y))

s1=solve([f(x,y)==1],x,y)
show(s1)


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

Sort by » oldest newest most voted

• 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.

more

Thanks it works!

Here for everyone the code to show it:

# Solve an equation an use the solution
mysol=solve([2+x^2==-1],x)
show(mysol)

G = x^3-i
show(G)

newG=G.subs(mysol)
show(newG)

[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)
f.trig_reduce()
show(f)

s1=solve([f(x,y)==1],x,y)
show(s1)


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

more

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