On Apr 9, 10:23 pm, nkulmati <[email protected]> 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.
>

"load" is not ignoring "G.plot()". The function is actually executed,
but the return value is lost. It can be assigned to a variable with:

    my_plot_object = G.plot()

There's a couple of things you can do to see your output.

In the case of "G.plot()", that function returns a graphics object. To
save your plot as an image, you can do something such as:

    G.plot.save("my_plot.png")

See: [http://www.sagemath.org/doc/reference/sage/plot/
plot.html#sage.plot.plot.Graphics.save]
for more information.

In the Sage notebook, if "G.plot()" is not the last line of a cell,
the return value is similarly thrown away. In the notebook,
additionally, the output can be directly shown with:

    G.plot().show()

See: [http://www.sagemath.org/doc/reference/sage/plot/
plot.html#sage.plot.plot.Graphics.show]
for more information.

If you want to output some line of text, you'll need to use the print
statement. If "my_result" is the variable containing the result of
your computation, you can use:

    print my_result

Same story for the notebook as explained above.

> How can I use sage to run scripts that involve real-time plotting and
> other output?

I'm not sure what you mean by this. You can try looking at the
@interact decorator in the Sage notebook.

As an unrelated side note, you can also run sage scripts directly from
the command line with:

    sage my_sage_script.sage

This will work if you add your sage installation directory to your
$PATH variable. See "sage --help" for more info.

Hope this answers some of your questions.

-- Kelvin

-- 
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