Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @stockh0lm. This seems to be a problem with the preprocessor, since it is assuming all \ to be a matrix operation (i.e., the Matlab-style operator for solving systems of linear equations).

As a workaround you could use consistent indentation. The following worked for me:

phi(epsilon, Q, r) = 1/(4*pi 
                     * epsilon
                     )*Q/r

show(phi(1,2,3))

Notice all lines defining phi are equally indented. Also, I am using the PEP 8 convention of breaking a line BEFORE an operator, i.e., the asterisk doesn't end a line, but it starts one. (This last convention has nothing to do with the working of the code; it's just a convention.)

Hello, @stockh0lm. This seems to be a problem with the preprocessor, since it is assuming all \ to be a matrix operation (i.e., the Matlab-style operator for solving systems of linear equations).

As a workaround you could use consistent indentation. indentation and wrap the code with parenthesis, so that Sage's preparser understands the complete extension of your code. The following worked for me:

phi(epsilon, Q, r) = 1/(4*pi 
                     (1 / (4 * epsilon
                     )*Q/r
pi 
                     * epsilon)
                     * Q / r)

show(phi(1,2,3))

Notice all lines defining phi are equally indented. indented, and I started and finished its definition with parenthesis. The preparser seems to assume the code defining the function ends on the line with the last parenthesis, so we are forcing it to consider our complete definition. The consistent indentation is Python's rule and a good programming style.

Also, I am using the PEP 8 convention of breaking a line BEFORE an operator, i.e., the asterisk doesn't end a line, but it starts one. (This last convention has nothing to do with the working of the code; it's just a convention.)

Hello, @stockh0lm. This seems to be a problem with the preprocessor, since it is assuming all \ to be a matrix operation (i.e., the Matlab-style operator for solving systems of linear equations).

As a workaround you could use consistent indentation and wrap the code with parenthesis, so that Sage's preparser understands the complete extension of your code. The following worked for me:

phi(epsilon, Q, r) = (1 / (4 * pi 
                     * epsilon)
                     * Q / r)

show(phi(1,2,3))

Notice all lines defining phi are equally indented, and I started and finished its definition with parenthesis. The preparser seems to assume the code defining the function ends on the line with the last parenthesis, so we are forcing it to consider our complete definition. The consistent indentation is Python's rule and a good programming style.definition.

Also, I am using the PEP 8 convention of breaking a line BEFORE an operator, i.e., the asterisk doesn't end a line, but it starts one. (This last convention has nothing to do with the working of the code; it's just a convention.)