Ask Your Question
2

Symbolic solve

asked 2012-02-11 11:56:41 +0100

Green diod gravatar image

updated 2020-08-07 13:07:41 +0100

slelievre 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

2 Answers

Sort by ยป oldest newest most voted
4

answered 2012-02-11 21:30:10 +0100

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 11:35:12 +0100 )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 12:12:22 +0100 )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 12:22:17 +0100 )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 13:56:46 +0100 )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 15:40:12 +0100 )edit
1

answered 2017-05-12 02:05:18 +0100

cybervigilante gravatar image

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.

edit flag offensive delete link more

Comments

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

cybervigilante gravatar imagecybervigilante ( 2017-05-12 02:09:59 +0100 )edit
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.

kcrisman gravatar imagekcrisman ( 2017-05-12 13:58:05 +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: 2012-02-11 11:56:41 +0100

Seen: 3,711 times

Last updated: Aug 07 '20