Ask Your Question
0

Symbolic solve

asked 2012-02-11 04:56:41 -0500

Green diod gravatar image

Following the change of variable thread, I wanted to streamline the whole process.

Namely, using the same example in the above thread, I'd like to say

integral_def_change(x*cos(x^2+1), (x, 0, 2*pi), u==x^2+1, u)

The difference is, I wanted also Sage to automatically solve for x instead of providing x= sqrt(u-1), say. But when I tried

solve(u==x^2+1, x)[0].rhs()

the output was r1 ???

1- What exactly is r1 ??

A way out (see this thread) seems to make of the solution a function of u

f(u)=solve(u==x^2+1, x)[0].rhs()

Now f is

u |--> -sqrt(u - 1)

2- What can I do to get +sqrt(u - 1) instead? Is this related to the positive function question there?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2012-02-11 14:30:10 -0500

kcrisman gravatar image
sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]

So you could use [1] instead of [0] to get the "positive" one.

I don't know how you got the r1 from this example, but the documentation for solve says, among other things:

   If there is a parameter in the answer, that will show up as a new
   variable.  In the following example, "r1" is a real free variable
   (because of the "r"):

      sage: solve([x+y == 3, 2*x+2*y == 6],x,y)
      [[x == -r1 + 3, y == r1]]

Hope this helps!

edit flag offensive delete link more

Comments

Ok, maybe my notebook was in a confused state :P In fact, I tend to go back to some previous cell, edit it and run it. But the big problem is, I don't know sometimes which cell was run and which was not. Going through all cells one by one is tedious.

Green diod gravatar imageGreen diod ( 2012-02-12 04:35:12 -0500 )edit

@Greendiod. What you can do in such a case is to put all the definitions you need and the problem you want to solve in one cell. So things cannot get out of sync.

petropolis gravatar imagepetropolis ( 2012-02-12 05:12:22 -0500 )edit

If the cell has many statements, isn't this going to take a long time each time I edit some little bit? And how to join two cells?

Green diod gravatar imageGreen diod ( 2012-02-12 05:22:17 -0500 )edit

If you click on the Help in the notebook and search for "join", you'll find that Ctrl-Backspace joins cells. As for the syncing, I don't think there is any easy way around this in any programming environment.

kcrisman gravatar imagekcrisman ( 2012-02-13 06:56:46 -0500 )edit

Ok, I also have found [this doc](http://www.sagemath.org/doc/reference/sagenb/notebook/config.html). As for the syncing, the problem is the notebook cell interface as I can randomly edit any cell.

Green diod gravatar imageGreen diod ( 2012-02-13 08:40:12 -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: 2012-02-11 04:56:41 -0500

Seen: 756 times

Last updated: Feb 11 '12