ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 12 May 2017 13:58:05 +0200Symbolic solvehttps://ask.sagemath.org/question/8707/symbolic-solve/Following the [change of variable thread](http://ask.sagemath.org/question/1113),
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](http://ask.sagemath.org/question/1105))
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](http://ask.sagemath.org/question/989)?Sat, 11 Feb 2012 11:56:41 +0100https://ask.sagemath.org/question/8707/symbolic-solve/Answer by cybervigilante for <p>Following the <a href="http://ask.sagemath.org/question/1113">change of variable thread</a>,
I wanted to streamline the whole process.</p>
<p>Namely, using the same example in the above thread, I'd like to say</p>
<pre><code>integral_def_change(x*cos(x^2+1), (x, 0, 2*pi), u == x^2 + 1, u)
</code></pre>
<p>The difference is, I wanted also Sage to automatically solve for <code>x</code>
instead of providing <code>x = sqrt(u - 1)</code>, say. But when I tried</p>
<pre><code>solve(u == x^2 + 1, x)[0].rhs()
</code></pre>
<p>the output was <code>r1</code>.</p>
<p>1- What exactly is r1 ??</p>
<p>A way out (see this <a href="http://ask.sagemath.org/question/1105">thread</a>)
seems to make of the solution a function of <code>u</code></p>
<pre><code>f(u) = solve(u == x^2 + 1, x)[0].rhs()
</code></pre>
<p>Now f is </p>
<pre><code>u |--> -sqrt(u - 1)
</code></pre>
<p>2- What can I do to get <code>+sqrt(u - 1)</code> instead? Is this related to the
<a href="http://ask.sagemath.org/question/989">positive function question there</a>?</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?answer=37579#post-id-37579I 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.Fri, 12 May 2017 02:05:18 +0200https://ask.sagemath.org/question/8707/symbolic-solve/?answer=37579#post-id-37579Comment by cybervigilante for <p>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.</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=37580#post-id-37580Although if you then declare r1: r1 = var('r1'), and insert it back into the deficient system of equations, they work out.Fri, 12 May 2017 02:09:59 +0200https://ask.sagemath.org/question/8707/symbolic-solve/?comment=37580#post-id-37580Comment by kcrisman for <p>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.</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=37582#post-id-37582Well, 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.Fri, 12 May 2017 13:58:05 +0200https://ask.sagemath.org/question/8707/symbolic-solve/?comment=37582#post-id-37582Answer by kcrisman for <p>Following the <a href="http://ask.sagemath.org/question/1113">change of variable thread</a>,
I wanted to streamline the whole process.</p>
<p>Namely, using the same example in the above thread, I'd like to say</p>
<pre><code>integral_def_change(x*cos(x^2+1), (x, 0, 2*pi), u == x^2 + 1, u)
</code></pre>
<p>The difference is, I wanted also Sage to automatically solve for <code>x</code>
instead of providing <code>x = sqrt(u - 1)</code>, say. But when I tried</p>
<pre><code>solve(u == x^2 + 1, x)[0].rhs()
</code></pre>
<p>the output was <code>r1</code>.</p>
<p>1- What exactly is r1 ??</p>
<p>A way out (see this <a href="http://ask.sagemath.org/question/1105">thread</a>)
seems to make of the solution a function of <code>u</code></p>
<pre><code>f(u) = solve(u == x^2 + 1, x)[0].rhs()
</code></pre>
<p>Now f is </p>
<pre><code>u |--> -sqrt(u - 1)
</code></pre>
<p>2- What can I do to get <code>+sqrt(u - 1)</code> instead? Is this related to the
<a href="http://ask.sagemath.org/question/989">positive function question there</a>?</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?answer=13267#post-id-13267 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!Sat, 11 Feb 2012 21:30:10 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?answer=13267#post-id-13267Comment by Green diod for <pre><code>sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]
</code></pre>
<p>So you could use <code>[1]</code> instead of <code>[0]</code> to get the "positive" one.</p>
<p>I don't know how you got the <code>r1</code> from this example, but the documentation for solve says, among other things:</p>
<pre><code> 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]]
</code></pre>
<p>Hope this helps!</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20289#post-id-20289Ok, 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.Mon, 13 Feb 2012 15:40:12 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20289#post-id-20289Comment by kcrisman for <pre><code>sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]
</code></pre>
<p>So you could use <code>[1]</code> instead of <code>[0]</code> to get the "positive" one.</p>
<p>I don't know how you got the <code>r1</code> from this example, but the documentation for solve says, among other things:</p>
<pre><code> 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]]
</code></pre>
<p>Hope this helps!</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20296#post-id-20296If 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.Mon, 13 Feb 2012 13:56:46 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20296#post-id-20296Comment by Green diod for <pre><code>sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]
</code></pre>
<p>So you could use <code>[1]</code> instead of <code>[0]</code> to get the "positive" one.</p>
<p>I don't know how you got the <code>r1</code> from this example, but the documentation for solve says, among other things:</p>
<pre><code> 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]]
</code></pre>
<p>Hope this helps!</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20302#post-id-20302If 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?Sun, 12 Feb 2012 12:22:17 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20302#post-id-20302Comment by petropolis for <pre><code>sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]
</code></pre>
<p>So you could use <code>[1]</code> instead of <code>[0]</code> to get the "positive" one.</p>
<p>I don't know how you got the <code>r1</code> from this example, but the documentation for solve says, among other things:</p>
<pre><code> 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]]
</code></pre>
<p>Hope this helps!</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20304#post-id-20304@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.Sun, 12 Feb 2012 12:12:22 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20304#post-id-20304Comment by Green diod for <pre><code>sage: var('u')
u
sage: solve(u==x^2+1, x)
[x == -sqrt(u - 1), x == sqrt(u - 1)]
</code></pre>
<p>So you could use <code>[1]</code> instead of <code>[0]</code> to get the "positive" one.</p>
<p>I don't know how you got the <code>r1</code> from this example, but the documentation for solve says, among other things:</p>
<pre><code> 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]]
</code></pre>
<p>Hope this helps!</p>
https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20306#post-id-20306Ok, 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.Sun, 12 Feb 2012 11:35:12 +0100https://ask.sagemath.org/question/8707/symbolic-solve/?comment=20306#post-id-20306