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

2 answers

Sort by ยป oldest newest most voted
4

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
0

answered 2017-05-11 19:05:18 -0500

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-11 19:09:59 -0500 )edit

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 06:58:05 -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: 904 times

Last updated: May 11