Ask Your Question
1

Simplify, Solve Equation and use solution

asked 2011-01-28 03:07:13 -0500

manifold gravatar image

updated 2011-01-28 03:18:02 -0500

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
5

answered 2011-01-28 03:33:45 -0500

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 03:37:57 -0500 )edit
3

answered 2011-01-28 03:59:18 -0500

manifold gravatar image

updated 2011-01-28 04:07:17 -0500

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 04:17:09 -0500 )edit

thanks! it works.

manifold gravatar imagemanifold ( 2011-01-28 04:27:49 -0500 )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 03:07:13 -0500

Seen: 8,400 times

Last updated: Jan 28 '11