Ask Your Question
0

Difficulty with sagetex

asked 2013-09-25 09:23:39 -0500

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 11:55:50 -0500 )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 16:45:45 -0500 )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 04:43:04 -0500 )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 04:46:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-09-25 10:47:17 -0500

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 09:23:39 -0500

Seen: 178 times

Last updated: Sep 25 '13