Ask Your Question
1

Piecewise in SageTeX

asked 2019-02-03 01:17:24 +0100

Martin Mårtensson gravatar image

Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX.

I tried different ways of typing the piecewise command in sage terminal and it works fine.

sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])

and

sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]);  f

But when i do the same in sagetex and compile with

# sage filename.sagetex.sage

Then i get

Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
 result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
 exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505) 
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)

**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
   """, globals(), locals(), False)
 File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
   splitup = self.split_sage_cmds(s)
 File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
   starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'

**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.

I tried inside env, sagecommandline and \sage{} and env. sageblock. I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.

Can anyone help me from here? How can i define piecewise functions in SageTeX??

edit retag flag offensive close merge delete

Comments

Can you post your LaTeX code? I have no trouble plotting the piecewise function you used with sagetex. Maybe I don't understand what you are attempting. Also, are you using Cocalc off the internet or is this compiled using Sage from your computer? If Sage from your computer, what version of Sage?

dazedANDconfused gravatar imagedazedANDconfused ( 2019-02-03 17:06:26 +0100 )edit

I forgot to write sage: ....

Martin Mårtensson gravatar imageMartin Mårtensson ( 2019-02-10 14:12:53 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2019-02-03 14:24:53 +0100

Emmanuel Charpentier gravatar image

Somebody called gh-JCGoran seems to have stumbled on this already, and reported Trac#27078.

But the implementation isn't trivial.

I also note that the sympy representatin of this function is questionable...

edit flag offensive delete link more
0

answered 2019-02-10 14:11:52 +0100

Martin Mårtensson gravatar image

I found out that i made a very silly mistake. I forgot to write

sage:

Before miy command. I was very tired and had been looking myself blind on the code. I realized this when i started to try writing other command that usually work, and they didnt work (ofcause) then i copy pasted some old code that worked and i realized that sage: was missing............................. x-) stupid me, Sorry for the inconvenience.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-02-03 01:17:24 +0100

Seen: 580 times

Last updated: Feb 10 '19