Ask Your Question
0

What's wrong with my function syntax?

asked 2015-04-01 12:41:28 -0600

PsylentKnight gravatar image

updated 2015-04-01 13:27:45 -0600

I've been using sagemath throughout the semester with few problems, but I just can't seem to figure out what's wrong with my syntax here.

x = var('x')

p(x) = x^3 – 3*x^2 + (x - 1)
Dp(x) = derivative(p(x), x)

plot(p(x), -1, 1)

I'm getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_2.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eCA9IHZhcigneCcpCgpwKHgpID0geF4zIOKAkyAzKnheMiArICh4IC0gMSkKRHAoeCkgPSBkZXJpdmF0aXZlKHAoeCksIHgpCgpwbG90KHAoeCksIC0xLCAxKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpd2XXUV/___code___.py", line 5
    __tmp__=var("x"); p = symbolic_expression(x**_sage_const_3  – _sage_const_3 *x**_sage_const_2  + (x - _sage_const_1 )).function(x)
                                                                ^
SyntaxError: invalid syntax

So appears that the function is in error...

I've been using sagemath throughout the semester with few problems, but I just can't seem to figure out what's wrong with my syntax here.

x = var('x')

p(x) = x^3 – 3*x^2 + x - 1
Dp(x) = derivative(p(x), x)

plot(p(x), -1, 1)

I'm getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_2.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("eCA9IHZhcigneCcpCgpwKHgpID0geF4zIOKAkyAzKnheMiArICh4IC0gMSkKRHAoeCkgPSBkZXJpdmF0aXZlKHAoeCksIHgpCgpwbG90KHAoeCksIC0xLCAxKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmpd2XXUV/___code___.py", line 5
    __tmp__=var("x"); p = symbolic_expression(x**_sage_const_3  – _sage_const_3 *x**_sage_const_2  + (x - _sage_const_1 )).function(x)
                                                                ^
SyntaxError: invalid syntax

So appears that the function is in error...

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2015-04-01 13:27:13 -0600

kcrisman gravatar image

There is something wrong with the character you input for "minus".

Compare:

p(x) = x^3 – 3*x^2 + (x - 1)

p(x) = x^3 - 3*x^2 + (x - 1)

At least on my computer, the first thing looks slightly longer, and is probably a dash or hyphen character of some kind. I don't have access to your computer, so I don't know what your keyboard looks like, but my guess is you are using something that looks like minus but isn't. Indeed,

sage: str('–')
'\xe2\x80\x93'
edit flag offensive delete link more

Comments

Thank you! It was probably because I pasted it from an outside source (probably the .pdf the instructions the professor gave us were in).

PsylentKnight gravatar imagePsylentKnight ( 2015-04-01 13:50:13 -0600 )edit

Ah, that would do it!

kcrisman gravatar imagekcrisman ( 2015-04-01 20:29:39 -0600 )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: 2015-04-01 12:41:28 -0600

Seen: 694 times

Last updated: Apr 01 '15