ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 18 Oct 2019 11:11:54 -0500Solve failshttps://ask.sagemath.org/question/48390/solve-fails/I wonder why the Variable 'x_0' not found
gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2Thu, 17 Oct 2019 23:50:09 -0500https://ask.sagemath.org/question/48390/solve-fails/Comment by Cyrille for <p>I wonder why the Variable 'x_0' not found</p>
<pre><code> gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2
</code></pre>
https://ask.sagemath.org/question/48390/solve-fails/?comment=48394#post-id-48394I was expecting thant $x_0$ will be taken as a parameter.Fri, 18 Oct 2019 03:58:50 -0500https://ask.sagemath.org/question/48390/solve-fails/?comment=48394#post-id-48394Comment by ortollj for <p>I wonder why the Variable 'x_0' not found</p>
<pre><code> gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2
</code></pre>
https://ask.sagemath.org/question/48390/solve-fails/?comment=48393#post-id-48393because there is an infinity of solutions x_0,x_1 in R
eq=70==(6*x_0+18*x_1).subs(x_1=7/8)
lin=solve(eq,x_0)
show("lin : ",lin)
eq=70==(6*x_0+18*x_1).subs(x_0=3/5)
lin=solve(eq,x_1)
show("lin : ",lin)Fri, 18 Oct 2019 03:43:17 -0500https://ask.sagemath.org/question/48390/solve-fails/?comment=48393#post-id-48393Answer by dsejas for <p>I wonder why the Variable 'x_0' not found</p>
<pre><code> gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2
</code></pre>
https://ask.sagemath.org/question/48390/solve-fails/?answer=48406#post-id-48406Hello, @Cyrille! Try the following:
gr = Polyhedron(ieqs=[(10,-1,0), (-12,0,1)])
p1 = gr.plot()
x_0, x_1 = var('x_0 x_1')
lin = solve([70==6*x_0+18*x_1], x_1, solution_dict=True)
p2 = plot(lin[0][x_1], (x_0,8,14))
p1 + p2
Notice I have added `solution_dict=True`, which makes `lin` a list of dictionaries of solutions:
[{x_1: -1/3*x_0 + 35/9}]
In order to plot it, first extract the dictionary from the list (that is done with `lin[0]`); we get
{x_1: -1/3*x_0 + 35/9}
Finally, we extract the equation you want to plot (that is done with `lin[0][x_1]`); we get
-1/3*x_0 + 35/9
That is what I used in the `plot` command.
**Note:** It is not necessary to use `(x_0, 8, 14)` in the `plot` command; you can use `(x, 8, 14)`. I did that to be consistent with notation.
There are a couple of things that bother me:
1. The polyhedron is too small in the plot, because the line is too far. Is this a problem for you?
2. This won't work if `x_1` has more than one solution.
Problem 2 is solved using tmontiel's suggestion.
There may be an alternative way to achieve the same thing. May I ask: what are you trying to achieve?Fri, 18 Oct 2019 11:11:54 -0500https://ask.sagemath.org/question/48390/solve-fails/?answer=48406#post-id-48406Answer by tmonteil for <p>I wonder why the Variable 'x_0' not found</p>
<pre><code> gr=Polyhedron(ieqs=[(10,-1,0),(-12,0,1)])
p1=gr.plot()
x_0, x_1 = var('x_0 x_1')
lin=solve([70==6*x_0+18*x_1],x_1)
p2=plot(lin, (x,8,14))
p1+p2
</code></pre>
https://ask.sagemath.org/question/48390/solve-fails/?answer=48395#post-id-48395This is very unclear. For `p2`, if you want an implicit plot where `x_0` is a parameter that belongs to the interval $[8,14]$, you can do:
sage: p2 = implicit_plot(70==6*x_0+18*x_1,(8,14),(-3,3))
You can also have a look to the `parametric_plot` function.
But without more details about your actual goal, there is not much to say.Fri, 18 Oct 2019 06:34:51 -0500https://ask.sagemath.org/question/48390/solve-fails/?answer=48395#post-id-48395