Ask Your Question

Felix Lawrence's profile - activity

2016-10-15 05:58:05 -0600 received badge  Great Answer (source)
2015-02-08 03:33:07 -0600 received badge  Taxonomist
2013-11-19 04:48:42 -0600 received badge  Good Answer (source)
2013-01-25 05:50:45 -0600 received badge  Nice Answer (source)
2013-01-05 23:03:33 -0600 received badge  Great Answer (source)
2012-05-04 15:42:01 -0600 received badge  Guru (source)
2012-05-04 15:42:01 -0600 received badge  Great Answer (source)
2012-01-05 16:17:20 -0600 received badge  Guru (source)
2012-01-05 16:17:20 -0600 received badge  Great Answer (source)
2011-12-26 23:00:15 -0600 received badge  Good Answer (source)
2011-12-26 22:37:07 -0600 received badge  Nice Answer (source)
2011-12-26 11:05:10 -0600 answered a question Can I add mathematical formulas to a plot?

Shashank told you how to do it in matplotlib (which comes with Sage) - matplotlib allows you a lot of control over your plots (I often use it for this reason), but as you can see, it involves a fair bit of boilerplate compared to Sage's plotting.

If you want to add a formula to a Sage plot, then you can just use latex inside dollar signs, like you would in a .tex document:

text(r"Here's a formula $\frac{\sqrt{3}}{2}$ and some text",(1,2))

Here the r" is necessary due to all the slashes in the string–if you don't include the r then you'll have to escape each of the slashes (check out the python String documentation for more info on that).

2011-12-23 21:56:53 -0600 received badge  Good Answer (source)
2011-12-21 13:41:50 -0600 received badge  Good Answer (source)
2011-12-21 13:33:49 -0600 received badge  Nice Answer (source)
2011-12-21 05:18:24 -0600 received badge  Nice Answer (source)
2011-12-21 02:27:58 -0600 answered a question Reliability of Sage vs commercial software

Compared to Mathematica 6.0.1 (the version of mathematica i bought - without paying more, they won't even let me have version 6.0.2 which fixed a bug I encountered), I have found Sage to be more reliable for what I do.

The most important difference is ease of debugging. When you make a mistake, Mathematica plows on. For example, if you forget to define a variable, Mathematica assumes it's symbolic and will keep going until it crashes, hangs, generates a meaningless expression, or you treat it as a list and slice it. if you're lucky Mathematica will give meaningless errors along the way that are hard to trace back to the problem (e.g. they occur 400 lines after the initial problem, and do not mention variable names or line numbers). If you make such a mistake in Sage, it will straight away throw up an error message with a traceback, which makes for MUCH faster debugging.

In my few years' experience using Sage, I have run into several parts that were rough around the edges (e.g. interaction with Mathematica, and to a lesser extent numpy/scipy), and found one bug that silently gave me incorrect answers (returning a vector as a row vector instead of a column vector). But then I also found an issue with Mathematica, where results were qualitatively different depending on whether it was run from a notebook or a command line (which turned out to be 32-bit vs 64-bit).

Still, I find it harder to write code that silently gives the wrong answer in Sage than in Mathematica, and it is also much easier to write code that gives the correct answer in Sage than to do the same in Mathematica, due to the errors and tracebacks that Sage provides. Sage almost always gives errors when something goes wrong, which helps you work around its inconsistencies, unlike mathematica, which hopes for the best and gives no advice as to how to work around its inconsistencies.

I have had to write my own functions and do lots of numerics - both things which Sage (which incorporates Python and SciPy) is very well suited to, and Mathematica is poorly suited to.

Other advantages Sage has, like redo/multiple level undo (provided by your text editor, or to a limited extent in your browser) are just gravy.

I don't have too much experience with symbolics. The one time I tried a full_simplify, I got a better result in Sage than in Mathematica, which surprised me.

But the biggest advantage of Sage's price tag is that you have a perpetual free trial. So give it a go - try reproducing some of your Mathematica results in Sage, and see whether it's up to scratch for your needs.

2011-12-05 10:03:29 -0600 answered a question font size in matplotlib

yticks(fontsize=SIZE) should work:

import pylab
import matplotlib
pylab.clf()
#pylab.rc('text', fontsize=18) #This is a 'bad' but effective way to change the default font size
pylab.plot(xdata, ydata, '--')
pylab.xlabel(r"$x$",fontsize=24)
pylab.ylabel(r"$y$",fontsize=24)
pylab.yticks(fontsize=40)
pylab.yticks(fontsize=40)
pylab.savefig('transspeclin.pdf', format='pdf')
pylab.savefig('transspeclin')
pylab.show()
2011-11-08 23:01:59 -0600 commented answer sage notebook server + ssh tunneling + port forwarding

I find it useful to run the `./sage -notebook` command from inside a `screen`, so that when I close the SSH tunnel, the Sage server and the worksheets keep running.

2011-10-29 03:44:52 -0600 received badge  Guru (source)
2011-10-29 03:44:52 -0600 received badge  Great Answer (source)
2011-10-09 11:35:56 -0600 received badge  Nice Answer (source)
2011-09-18 23:59:17 -0600 received badge  Good Answer (source)
2011-09-10 17:32:29 -0600 commented answer How can I share code between worksheets?

The best way to do it would be to let Virtual Box see the windows directories that you're saving the files in, and give that as the path. I don't have Windows, but on my Mac version of VirtualBox there is a Devices menu with a "Shared Folders..." item, that will set this up. Hopefully you can then work out the path of the shared folder - I guess you should ask a separate question for that, someone with more specific knowledge may be able to help.

2011-09-10 17:32:29 -0600 received badge  Commentator
2011-09-06 15:24:24 -0600 received badge  Nice Answer (source)
2011-09-05 16:10:51 -0600 answered a question How can I share code between worksheets?

You can write your reuseable functions into a .sage or .py file, store it anywhere on your computer (or the web), and then somewhere in the worksheet (e.g. the top), have a cell with

%auto
attach('/path/to/my/file.py')

attach will run all the code in your file, every time the file changes, so the functions in the file will be available from the worksheet.

2011-08-31 13:30:29 -0600 received badge  Enthusiast
2011-06-23 17:29:16 -0600 received badge  Good Answer (source)
2011-06-23 15:53:38 -0600 received badge  Nice Answer (source)
2011-06-23 14:46:54 -0600 answered a question SAGE and GPUs

Some work has been done to integrate PyCUDA and PyOpenCL into Sage. There are details on trac about how to install them: PyCUDA and PyOpenCL.

I think a lot of people would be happy if these were integrated into Sage.

2011-04-30 05:48:23 -0600 received badge  Nice Answer (source)
2011-04-29 22:54:27 -0600 answered a question Sage relation to Python

The Sage notebook doesn't replace a good text editor. It's fantastic for writing 'on the fly' code and for calling pre-written functions, but as far as I know, there's no handy GUI in the notebook for opening, manually editing and saving .py files.

There is, however, very neat support for executing .py and .sage files. The load and attach commands are explained in the tutorial and work both for .sage files and for .py files. attach will automatically reload the file every time it is changed. The preparser is not called for .py files, so you have to import any sage functions that you want to use.

You can set the path for load and attach using load_attach_path.

2011-04-27 13:09:30 -0600 commented answer Updating scipy in sage

@flutefreak7: sage 4.7 is about to be released in the next few days i think (it's currently at release candidate 0), and it includes scipy 0.9 - so hang tight!

2011-04-19 05:30:37 -0600 received badge  Enlightened (source)
2011-04-19 05:30:33 -0600 received badge  Good Answer (source)
2011-04-19 03:36:23 -0600 received badge  Nice Answer (source)
2011-04-19 03:26:47 -0600 answered a question Physics constants in sage.

Scipy, included in sage, has these constants:

sage: from scipy.constants import h, k
sage: h
6.6260693000000002e-34
sage: k
1.3806505000000001e-23

More details about what is in scipy.constants is available here

2011-04-10 20:36:18 -0600 answered a question Using Sage Symbolic Functions in Scipy fsolve

This is one of the problems you're having:

sage: ff(scipy.array([1,1]))
TypeError: no canonical coercion from <type 'numpy.int64'> to Symbolic Ring

Which can be remedied as such:

sage: ff(scipy.array([1.,1.]))
2

But this merely exposes another problem:

sage: scipy.optimize.fsolve(ff, scipy.array([1.,1.]))
TypeError: There is a mismatch between the input and output shape of ff.

And I don't know how to solve that one.

2011-03-22 04:30:28 -0600 received badge  Organizer (source)
2011-03-22 04:27:40 -0600 commented answer can gridlines be painted at sqrt(2) ?

Don't forget the most compact option: sqrt(2.)

2011-03-20 21:30:19 -0600 received badge  Nice Answer (source)
2011-03-18 22:51:45 -0600 answered a question How do instantiate a new class properly?

Instead of "from feynman import *", try "attach feynman.sage" - my guess is that if you use the from ... import syntax then the .sage file is treated like a .py file rather than sage code.

2011-03-17 19:00:30 -0600 received badge  Good Answer (source)
2011-03-17 18:05:54 -0600 commented answer symbolic calculus on doubling points in elliptic curves

probably because it was merged 9 hours ago ;-)

2011-03-17 17:31:00 -0600 received badge  Nice Answer (source)
2011-03-17 16:34:38 -0600 received badge  Editor (source)
2011-03-17 16:31:13 -0600 answered a question symbolic calculus on doubling points in elliptic curves

In the next version of sage (4.7) you will be able to use the functions self_compose and nest to do this. Use nest when you want to find $f(f(...f(x)...))$ for known $x$, and use self_compose when you want a function that has not been evaluated.

In the meantime you'll need to define them yourself:

def nest(f, n, x):
    """Return `f(f(...f(x)...))`, where the composition occurs n times."""
    for i in xrange(n):
        x = f(x)
    return x

def self_compose(f, n):
    """Return the function `f` composed with itself `n` times."""
    return lambda x: nest(f, n, x)

For usage examples and more documentation, see the patch that adds this functionality. There is one example which is very similar to yours:

    sage: def f(x): return x^2 + 1
    sage: x = var('x')
    sage: nest(f, 3, x)
    ((x^2 + 1)^2 + 1)^2 + 1