Ask Your Question
2

Simplify, Solve Equation and use solution

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

manifold gravatar image

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

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)
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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
6

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

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

Comments

Beat me by three minutes. :^)

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

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

manifold gravatar image

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

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[0])
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)

edit flag offensive delete link more

Comments

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 +0100 )edit

thanks! it works.

manifold gravatar imagemanifold ( 2011-01-28 11:27:49 +0100 )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

Stats

Asked: 2011-01-28 10:07:13 +0100

Seen: 17,127 times

Last updated: Jan 28 '11