On Apr 9, 2011, at 22:23 , nkulmati wrote:

> Hi All, I am a newbie to Sage. My main purpose is to write scripts
> (algorithms). That is, I am not interested in the "answer-question"
> approach of the notebook, but I want to write and execute ".sage"
> files using sage just as I do with ".m" files using Matlab, for
> example.
> 
> So I found this page: http://www.sagemath.org/doc/tutorial/programming.html
> 
> However, when I use "load test.sage", everything works (variables get
> created and computed) but there is no output like the one I get by
> entering my algorithm line-by-line directly.
> 
> For example, the command "G.plot()" gets totally ignored by the "load'
> function.
> 
> How can I use sage to run scripts that involve real-time plotting and
> other output?

To enlarge on what Kelvin tells you, there are some differences between 
executing commands at the command prompt, and executing them from a script.

If you just list the commands in the script and then load it, some "side 
effects" (like invoking a program to display a plot) don't happen.

One way to do what you want is to assign the results of the graphics operations 
to variables, and then display them after the file is loaded.

Another approach is to return one or more graphics from a procedure you define 
in your script.  For example, if your script looked like

E=EllipticCurve("389a1")
E.plot()

then loading the script will not produce a plot.  Instead, make your script 
look like this:

def DoIt():
    E=EllipticCurve("389a1")
    return E.plot()

Then the "return values" that Kelvin mentions don't get lost.  With this in 
your script, at the sage prompt (after loading your script), use either

DoIt()

to get the plot displayed immediately, or

g = DoIt()

to save the plot for later use.  If you want to deal with multiple "values" 
that seem to be getting lost, return them all:
    return g1, g2, g3

These will be returned as a list, and you can invoke your function as

G=DoIt()   # G will be the list [g1,g2,g3]

or

g1,g2,g3=DoIt()

Others on the list may be able to shed more light.

HTH

Justin

--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's Income
-----------
Nobody knows the trouble I've been
-----------



-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to