ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Sep 2011 15:52:39 -0500basic algebra with several variables-why won't it work?http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/Hi,
I'm trying to use Sage-Notebook as a basic calculator and want to do some basic algebra for two variables. However, it keeps giving me syntax error messages when I type in the below. What am I doing wrong?
x, y = var('x, y')
solve([20*(6400-x-2y)==0, 80*(3200-x-y)==0], x, y)
Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax
Thank you!Mon, 26 Sep 2011 12:12:19 -0500http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/Answer by benjaminfjones for <p>Hi,</p>
<p>I'm trying to use Sage-Notebook as a basic calculator and want to do some basic algebra for two variables. However, it keeps giving me syntax error messages when I type in the below. What am I doing wrong?</p>
<p>x, y = var('x, y')
solve([20<em>(6400-x-2y)==0, 80</em>(3200-x-y)==0], x, y)</p>
<p>Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?answer=12683#post-id-12683You are using "implicit multiplication" which Sage does not understand by default (you can turn it on if you want). You should change `2y` above to `2*y` and `80(3200-x-y)` to `80*(3200-x-y)`, etc... Here is code that works:
x, y = var('x, y')
solve([20*(6400-x-2*y)==0, 80*(3200-x-y)==0], x, y)
Sage's output is:
[[x == 0, y == 3200]]
ps. Implicit multiplication can be turned on using: `implicit_multiplication(True)`, see the [preparser documentation.](http://www.sagemath.org/doc/reference/sage/misc/preparser.html)Mon, 26 Sep 2011 13:55:48 -0500http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?answer=12683#post-id-12683Comment by Hun for <p>You are using "implicit multiplication" which Sage does not understand by default (you can turn it on if you want). You should change <code>2y</code> above to <code>2*y</code> and <code>80(3200-x-y)</code> to <code>80*(3200-x-y)</code>, etc... Here is code that works:</p>
<pre><code>x, y = var('x, y')
solve([20*(6400-x-2*y)==0, 80*(3200-x-y)==0], x, y)
</code></pre>
<p>Sage's output is:</p>
<pre><code>[[x == 0, y == 3200]]
</code></pre>
<p>ps. Implicit multiplication can be turned on using: <code>implicit_multiplication(True)</code>, see the <a href="http://www.sagemath.org/doc/reference/sage/misc/preparser.html">preparser documentation.</a></p>
http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?comment=21196#post-id-21196Thanks for clearing that up for me :) Now I won't miss it!Mon, 26 Sep 2011 15:52:39 -0500http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?comment=21196#post-id-21196Answer by Mike Witt for <p>Hi,</p>
<p>I'm trying to use Sage-Notebook as a basic calculator and want to do some basic algebra for two variables. However, it keeps giving me syntax error messages when I type in the below. What am I doing wrong?</p>
<p>x, y = var('x, y')
solve([20<em>(6400-x-2y)==0, 80</em>(3200-x-y)==0], x, y)</p>
<p>Traceback (click to the left of this block for traceback)
...
SyntaxError: invalid syntax</p>
<p>Thank you!</p>
http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?answer=12691#post-id-12691Sage doesn't have "implicit" multiplication (by default). Try putting in "*" as a multiplication operator:
x, y = var('x, y')
solve([20*(6400-x-2*y)==0, 80*(3200-x-y)==0], x, y)
Mon, 26 Sep 2011 13:58:21 -0500http://ask.sagemath.org/question/8317/basic-algebra-with-several-variables-why-wont-it-work/?answer=12691#post-id-12691