# Symbolic solve

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

Sort by » oldest newest most voted
sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]


So you could use  instead of  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!

more

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.

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

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?

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.

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.

I got an r1 when I removed a row from a solvable system of equations, to make it deficient on purpose - I still got an answer but it contained r1s. I guess Sage means that, in a system of equations anyway, there is no answer or maybe infinite answers.

more

Although if you then declare r1: r1 = var('r1'), and insert it back into the deficient system of equations, they work out.

1

Well, yes, as I point out in my answer, r1 is the designation (via Maxima) for an arbitrary real variable. So if you get that in the solution, it means there is a degree of freedom in the linear algebra sense. Infinite answers, indeed.