Ask Your Question
0

Difficulty with sagetex

asked 2013-09-25 16:23:39 +0100

td01 gravatar image

Please forgive any short comings as I am new to sage, python and sagetex, perhaps I'm trying to run before I can walk or even crawl!

I am trying to run the the sageblock below to obtain the sequence 'S' and reference individual elements of the list 'S'. It works fine in Sage but cannot get any where with sagetex.

    \begin{sagesilent}
    def nmax(max=100):
        n = 1
        an = 20
       while n <= max:
          yield an
          n += 1
          an = 0.9*an-5

          a = nmax(30)
          S=[]
          for i in a:
          S.append(i.n())
\end{sagesilent}

produces the error

** Error in Sage code on line 36 of sequences01.tex! Traceback follows. Traceback (most recent call last):
File "sequences01.sagetex.py", line 43, in <module> _st_.inline(_sage_const_3 , latex(S)) NameError: name 'S' is not defined

When I try to access 'S' with $\sage{S}$, am beginning to feel at a loss as to where to look now.

edit retag flag offensive close merge delete

Comments

Many thanks kcrisman, works for me too now! Am going to have to study the indentation a bit more when typing into sagetex. Thanks a lot for your speedy response.

td01 gravatar imagetd01 ( 2013-09-25 18:55:50 +0100 )edit

No problem! Basically, just use four spaces after a colon. Going through one of the (many) Python tutorials out there wouldn't be a bad place to start.

kcrisman gravatar imagekcrisman ( 2013-09-25 23:45:45 +0100 )edit
1

Thanks again, went over a Python tutorial again and got to grips with indentation and a after a little experimentation found the 4 spaces for myself and all going well now! Thanks.

td01 gravatar imagetd01 ( 2013-09-29 11:43:04 +0100 )edit

By the way, I think Python actually accepts any consistent indentation, not just four spaces - but that is certainly the most common practice and easiest to read. You may be able to set up your editor to do this automatically after colons.

kcrisman gravatar imagekcrisman ( 2013-09-30 11:46:50 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-09-25 17:47:17 +0100

kcrisman gravatar image

I think your problem is indentation. This document works for me. Remember that indentation is syntax for Python.

%!TEX TS-program = sage
\documentclass[12pt]{article}
%In case I ever wanted to do horizontally
%\usepackage[landscape]{geometry}
\usepackage{amsmath,amssymb}
\usepackage[pdftex]{graphicx}
\usepackage{sagetex}


\begin{document}

\begin{sagesilent}
def nmax(max=100):
    n = 1
    an = 20
    while n <= max:
          yield an
          n += 1
          an = 0.9*an-5

a = nmax(30)
S=[]
for i in a:
     S.append(i.n())
\end{sagesilent}

$\sage{S}$

\end{document}
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

Stats

Asked: 2013-09-25 16:23:39 +0100

Seen: 455 times

Last updated: Sep 25 '13