maxima.eval
for long input
is much less robust, and is not recommended.
sage: t = '"%s"'%10^10000 # ten thousand character string. sage: a = maxima(t)
TESTS: This working tests that a subtle bug has been fixed:
sage: f = maxima.function('x','gamma(x)') sage: g = f(1/7) sage: g gamma(1/7) sage: del f sage: maxima(sin(x)) sin(x)
A long complicated input expression:
sage: maxima._eval_line('((((((((((0) + ((1) / ((n0) ^ (0)))) + ((1) / ((n1) ^ (1)))) + ((1) / ((n2) ^ (2)))) + ((1) / ((n3) ^ (3)))) + ((1) / ((n4) ^ (4)))) + ((1) / ((n5) ^ (5)))) + ((1) / ((n6) ^ (6)))) + ((1) / ((n7) ^ (7)))) + ((1) / ((n8) ^ (8)))) + ((1) / ((n9) ^ (9)));') '1/n9^9+1/n8^8+1/n7^7+1/n6^6+1/n5^5+1/n4^4+1/n3^3+1/n2^2+1/n1+1'
Module-level Functions
x) |
) |
) |
) |
parent, defn, args, latex) |
Class: Maxima
self, [script_subdirectory=None], [logfile=None], [server=None], [init_code=None]) |
Create an instance of the Maxima interpreter.
Functions: chdir,
clear,
completions,
console,
de_solve,
de_solve_laplace,
demo,
describe,
example,
function,
get,
help,
lisp,
plot2d,
plot2d_parametric,
plot3d,
plot3d_parametric,
plot_list,
plot_multilist,
set,
solve_linear,
trait_names,
version
self, dir) |
Change Maxima's current working directory.
sage: maxima.chdir('/')
self, var) |
Clear the variable named var.
self, s, [verbose=True]) |
Return all commands that complete the command starting with the string s. This is like typing s[tab] in the maple interpreter.
self) |
Start the interactive Maxima console. This is a completely separate maxima
session from this interface. To interact with this session, you should
instead use maxima.interact()
.
sage: maxima.console() # not tested (since we can't) Maxima 5.13.0 http://maxima.sourceforge.net Using Lisp CLISP 2.41 (2006-10-13) Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. This is a development version of Maxima. The function bug_report() provides bug reporting information. (%i1)
sage: maxima.interact() # this is not tested either --> Switching to Maxima <-- maxima: 2+2 4 maxima: --> Exiting back to SAGE <--
maxima, de, vars, [ics=None]) |
Solves a 1st or 2nd order ordinary differential equation (ODE) in two variables, possibly with initial conditions.
Input:
sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [1,1,1]) y=3*x-2*%e^(x-1) sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y']) y=%k1*%e^x+%k2*%e^-x+3*x sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y']) y=(%c-3*(-x-1)*%e^-x)*%e^x sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'],[1,1]) y=-%e^-1*(5*%e^x-3*%e*x-3*%e)
self, de, vars, [ics=None]) |
Solves an ordinary differential equation (ODE) using Laplace transforms.
Input:
sage: maxima.clear('x'); maxima.clear('f') sage: maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"], [0,1,2]) f(x)=x*%e^x+%e^x
sage: maxima.clear('x'); maxima.clear('f') sage: f = maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"]) sage: f f(x)=x*%e^x*(?%at('diff(f(x),x,1),x=0))-f(0)*x*%e^x+f(0)*%e^x sage: print f ! x d ! x x f(x) = x %e (-- (f(x))! ) - f(0) x %e + f(0) %e dx ! !x = 0
oteThe second equation sets the values of
and
in maxima, so subsequent ODEs involving these
variables will have these initial conditions automatically
imposed.
self, args, defn, [rep=None], [latex=None]) |
Return the Maxima function with given arguments and definition.
Input:
sage: f = maxima.function('x', 'sin(x)') sage: f(3.2) -.05837414342758009 sage: f = maxima.function('x,y', 'sin(x)+cos(y)') sage: f(2,3.5) sin(2)-.9364566872907963 sage: f sin(x)+cos(y)
sage: g = f.integrate('z') sage: g (cos(y)+sin(x))*z sage: g(1,2,3) 3*(cos(2)+sin(1))
The function definition can be a maxima object:
sage: an_expr = maxima('sin(x)*gamma(x)') sage: t = maxima.function('x', an_expr) sage: t gamma(x)*sin(x) sage: t(2) sin(2) sage: float(t(2)) 0.90929742682568171 sage: loads(t.dumps()) gamma(x)*sin(x)
self, var) |
Get the string value of the variable var.
self, cmd) |
Send a lisp command to maxima.
NOTE: The output of this command is very raw - not pretty.
sage: maxima.lisp("(+ 2 17)") # random formated output :lisp (+ 2 17) 19 (
self) |
Plot a 2d graph using Maxima / gnuplot.
maxima.plot2d(f, '[var, min, max]', options)
Input:
sage: maxima.plot2d('sin(x)','[x,-5,5]') # not tested sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]' sage: maxima.plot2d('sin(x)','[x,-5,5]',opts) # not tested
The eps file is saved in the current directory.
self, r, var, trange, [nticks=50], [options=None]) |
Plots r = [x(t), y(t)] for t = tmin...tmax using gnuplot with options
Input:
sage: maxima.plot2d_parametric(["sin(t)","cos(t)"], "t",[-3.1,3.1]) # not tested
sage: opts = '[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "circle-plot.eps"]' sage: maxima.plot2d_parametric(["sin(t)","cos(t)"], "t", [-3.1,3.1], options=opts) # not tested
The eps file is saved to the current working directory.
Here is another fun plot:
sage: maxima.plot2d_parametric(["sin(5*t)","cos(11*t)"], "t", [0,2*pi()], nticks=400) # not tested
self) |
Plot a 3d graph using Maxima / gnuplot.
maxima.plot3d(f, '[x, xmin, xmax]', '[y, ymin, ymax]', '[grid, nx, ny]', options)
Input:
sage: maxima.plot3d('1 + x^3 - y^2', '[x,-2,2]', '[y,-2,2]', '[grid,12,12]') # not tested sage: maxima.plot3d('sin(x)*cos(y)', '[x,-2,2]', '[y,-2,2]', '[grid,30,30]') # not tested sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]' sage: maxima.plot3d('sin(x+y)', '[x,-5,5]', '[y,-1,1]', opts) # not tested
The eps file is saved in the current working directory.
self, r, vars, urange, vrange, [options=None]) |
Plot a 3d parametric graph with r=(x,y,z), x = x(u,v), y = y(u,v), z = z(u,v), for u = umin...umax, v = vmin...vmax using gnuplot with options.
Input:
x="u2+v2"
, ...)
vars is a list or two strings representing variables (such as vars = ["u","v"])
sage: maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-3.2,3.2],[0,3]) # not tested sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-cos-plot.eps"]' sage: maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-3.2,3.2],[0,3],opts) # not tested
The eps file is saved in the current working directory.
Here is a torus:
sage: _ = maxima.eval("expr_1: cos(y)*(10.0+6*cos(x)); expr_2: sin(y)*(10.0+6*cos(x)); expr_3: -6*sin(x);") # optional sage: maxima.plot3d_parametric(["expr_1","expr_2","expr_3"], ["x","y"],[0,6],[0,6]) # not tested
Here is a Mobius strip:
sage: x = "cos(u)*(3 + v*cos(u/2))" sage: y = "sin(u)*(3 + v*cos(u/2))" sage: z = "v*sin(u/2)" sage: maxima.plot3d_parametric([x,y,z],["u","v"],[-3.1,3.2],[-1/10,1/10]) # not tested
self, ptsx, ptsy, [options=None]) |
Plots a curve determined by a sequence of points.
Input:
The points are (x1,y1), (x2,y2), etc.
This function requires maxima 5.9.2 or newer.
Note: More that 150 points can sometimes lead to the program hanging. Why?
sage: zeta_ptsx = [ (pari(1/2 + i*I/10).zeta().real()).precision(1) for i in range (70,150)] sage: zeta_ptsy = [ (pari(1/2 + i*I/10).zeta().imag()).precision(1) for i in range (70,150)] sage: maxima.plot_list(zeta_ptsx, zeta_ptsy) # not tested sage: opts='[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "zeta.eps"]' sage: maxima.plot_list(zeta_ptsx, zeta_ptsy, opts) # not tested
self, pts_list, [options=None]) |
Plots a list of list of points pts_list=[pts1,pts2,...,ptsn], where each ptsi is of the form [[x1,y1],...,[xn,yn]] x's must be integers and y's reals options is a string representing maxima plot2d options.
Requires maxima 5.9.2 at least. Note: More that 150 points can sometimes lead to the program hanging.
sage: xx = [ i/10.0 for i in range (-10,10)] sage: yy = [ i/10.0 for i in range (-10,10)] sage: x0 = [ 0 for i in range (-10,10)] sage: y0 = [ 0 for i in range (-10,10)] sage: zeta_ptsx1 = [ (pari(1/2+i*I/10).zeta().real()).precision(1) for i in range (10)] sage: zeta_ptsy1 = [ (pari(1/2+i*I/10).zeta().imag()).precision(1) for i in range (10)] sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1],[xx,y0],[x0,yy]]) # not tested sage: zeta_ptsx1 = [ (pari(1/2+i*I/10).zeta().real()).precision(1) for i in range (10,150)] sage: zeta_ptsy1 = [ (pari(1/2+i*I/10).zeta().imag()).precision(1) for i in range (10,150)] sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1],[xx,y0],[x0,yy]]) # not tested sage: opts='[gnuplot_preamble, "set nokey"]' sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1],[xx,y0],[x0,yy]],opts) # not tested
self, var, value) |
Set the variable var to the given value.
Input:
self, eqns, vars) |
Wraps maxima's linsolve.
Input: eqns is a list of m strings, each rperesenting a linear question in m <= n variables vars is a list of n strings, each representing a variable
sage: eqns = ["x + z = y","2*a*x - y = 2*a^2","y - 2*z = 2"] sage: vars = ["x","y","z"] sage: maxima.solve_linear(eqns, vars) [x=a+1,y=2*a,z=a-1]
self, [verbose=True], [use_disk_cache=True]) |
Return all Maxima commands, which is useful for tab completion.
sage: len(maxima.trait_names(verbose=False)) # random output 1743
self) |
Return the version of Maxima that Sage includes.
sage: maxima.version() '5.13.0'
Special Functions: __call__,
__init__,
__reduce__,
_batch,
_before,
_commands,
_crash_msg,
_error_check,
_error_msg,
_eval_line,
_expect_expr,
_false_symbol,
_interrupt,
_object_class,
_quit_string,
_sendline,
_sendstr,
_start,
_synchronize,
_true_symbol
self, [verbose=True]) |
Return list of all commands defined in Maxima.
self) |
Return the false symbol in Maxima.
sage: maxima._false_symbol() 'false' sage: maxima.eval('is(2 = 4)') 'false'
self) |
Return the Python class of Maxima elements.
sage: maxima._object_class() <class 'sage.interfaces.maxima.MaximaElement'>
self) |
Synchronize pexpect interface.
This put a random integer (plus one!) into the output stream, then waits for it, thus resynchronizing the stream. If the random integer doesn't appear within 1 second, maxima is sent interrupt signals.
This way, even if you somehow left maxima in a busy state computing, calling _synchronize gets everything fixed.
This makes Maxima start a calculation:
sage: maxima._sendstr('1/1'*500)
When you type this command, this synchronize command is implicitly called, and the above running calculation is interrupted:
sage: maxima('2+2') 4
self) |
Return the true symbol in Maxima.
sage: maxima._true_symbol() 'true' sage: maxima.eval('is(2 = 2)') 'true'
Class: MaximaElement
Functions: comma,
derivative,
diff,
display2d,
dot,
imag,
integral,
integrate,
nintegral,
numer,
partial_fraction_decomposition,
real,
str,
subst,
trait_names
self, args) |
Form the expression that would be written 'self, args' in Maxima.
sage: maxima('sqrt(2) + I').comma('numer') I+1.414213562373095 sage: maxima('sqrt(2) + I*a').comma('a=5') 5*I+sqrt(2)
self, [var=x], [n=1]) |
Return the n-th derivative of self.
Input:
sage: f = maxima('x^2') sage: f.diff() 2*x sage: f.diff('x') 2*x sage: f.diff('x', 2) 2 sage: maxima('sin(x^2)').diff('x',4) 16*x^4*sin(x^2)-12*sin(x^2)-48*x^2*cos(x^2)
sage: f = maxima('x^2 + 17*y^2') sage: f.diff('x') 34*y*'diff(y,x,1)+2*x sage: f.diff('y') 34*y
self, [var=x], [n=1]) |
Return the n-th derivative of self.
Input:
sage: f = maxima('x^2') sage: f.diff() 2*x sage: f.diff('x') 2*x sage: f.diff('x', 2) 2 sage: maxima('sin(x^2)').diff('x',4) 16*x^4*sin(x^2)-12*sin(x^2)-48*x^2*cos(x^2)
sage: f = maxima('x^2 + 17*y^2') sage: f.diff('x') 34*y*'diff(y,x,1)+2*x sage: f.diff('y') 34*y
self, [onscreen=True]) |
sage: F = maxima('x^5 - y^5').factor() sage: F.display2d () 4 3 2 2 3 4 - (y - x) (y + x y + x y + x y + x )
self, other) |
Implements the notation self . other.
sage: A = maxima('matrix ([a1],[a2])') sage: B = maxima('matrix ([b1, b2])') sage: A.dot(B) matrix([a1*b1,a1*b2],[a2*b1,a2*b2])
self) |
Return the imaginary part of this maxima element.
sage: maxima('2 + (2/3)*%i').imag() 2/3
self, [var=x], [min=None], [max=None]) |
Return the integral of self with respect to the variable x.
Input:
Returns the definite integral if xmin is not None, otherwise returns an indefinite integral.
sage: maxima('x^2+1').integral() x^3/3+x sage: maxima('x^2+ 1 + y^2').integral('y') y^3/3+x^2*y+y sage: maxima('x / (x^2+1)').integral() log(x^2+1)/2 sage: maxima('1/(x^2+1)').integral() atan(x) sage: maxima('1/(x^2+1)').integral('x', 0, infinity) %pi/2 sage: maxima('x/(x^2+1)').integral('x', -1, 1) 0
sage: f = maxima('exp(x^2)').integral('x',0,1); f -sqrt(%pi)*%i*erf(%i)/2 sage: f.numer() # I wonder how to get a real number (~1.463)?? -.8862269254527579*%i*erf(%i)
self, [var=x], [min=None], [max=None]) |
Return the integral of self with respect to the variable x.
Input:
Returns the definite integral if xmin is not None, otherwise returns an indefinite integral.
sage: maxima('x^2+1').integral() x^3/3+x sage: maxima('x^2+ 1 + y^2').integral('y') y^3/3+x^2*y+y sage: maxima('x / (x^2+1)').integral() log(x^2+1)/2 sage: maxima('1/(x^2+1)').integral() atan(x) sage: maxima('1/(x^2+1)').integral('x', 0, infinity) %pi/2 sage: maxima('x/(x^2+1)').integral('x', -1, 1) 0
sage: f = maxima('exp(x^2)').integral('x',0,1); f -sqrt(%pi)*%i*erf(%i)/2 sage: f.numer() # I wonder how to get a real number (~1.463)?? -.8862269254527579*%i*erf(%i)
self, [var=x], [a=0], [b=1], [desired_relative_error=1e-8], [maximum_num_subintervals=200]) |
Return a numerical approximation to the integral of self from a to b.
Input:
sage: maxima('exp(-sqrt(x))').nintegral('x',0,1) (.5284822353142306, 4.163314137883845E-11, 231, 0)
Note that GP also does numerical integration, and can do so to very high precision very quickly:
sage: gp('intnum(x=0,1,exp(-sqrt(x)))') 0.5284822353142307136179049194 # 32-bit 0.52848223531423071361790491935415653021 # 64-bit sage: _ = gp.set_precision(80) sage: gp('intnum(x=0,1,exp(-sqrt(x)))') 0.5284822353142307136179049193541565302167554758729286619686527932101540170 2040079
self) |
Return numerical approximation to self as a Maxima object.
sage: a = maxima('sqrt(2)').numer(); a 1.414213562373095 sage: type(a) <class 'sage.interfaces.maxima.MaximaElement'>
self, [var=x]) |
Return the partial fraction decomposition of self with respect to the variable var.
sage: f = maxima('1/((1+x)*(x-1))') sage: f.partial_fraction_decomposition('x') 1/(2*(x-1))-1/(2*(x+1)) sage: print f.partial_fraction_decomposition('x') 1 1 --------- - --------- 2 (x - 1) 2 (x + 1)
self) |
Return the real part of this maxima element.
sage: maxima('2 + (2/3)*%i').real() 2
self) |
Return string representation of this maxima object.
sage: maxima('sqrt(2) + 1/3').str() 'sqrt(2)+1/3'
self, val) |
Substitute a value or several values into this Maxima object.
sage: maxima('a^2 + 3*a + b').subst('b=2') a^2+3*a+2 sage: maxima('a^2 + 3*a + b').subst('a=17') b+340 sage: maxima('a^2 + 3*a + b').subst('a=17, b=2') 342
Special Functions: __call__,
__cmp__,
__complex__,
__float__,
__getitem__,
__iter__,
__len__,
__repr__,
__str__,
_complex_double_,
_complex_mpfr_field_,
_latex_,
_matrix_,
_mpfr_,
_real_double_,
_sage_
self, other) |
sage: a = maxima(1); b = maxima(2) sage: a == b False sage: a < b True sage: a > b False sage: b < a False sage: b > a True
We can also compare more complicated object such as functions:
sage: f = maxima('sin(x)'); g = maxima('cos(x)') sage: -f == g.diff('x') True
self) |
sage: complex(maxima('sqrt(-2)+1')) (1+1.4142135623730951j)
self) |
Return floating point version of this maxima element.
sage: float(maxima("3.14")) 3.1400000000000001 sage: float(maxima("1.7e+17")) 1.7e+17 sage: float(maxima("1.7e-17")) 1.6999999999999999e-17
self, n) |
Return the n-th element of this list.
Note: Lists are 0-based when accessed via the Sage interface, not 1-based as they are in the Maxima interpreter.
sage: v = maxima('create_list(i*x^i,i,0,5)'); v [0,x,2*x^2,3*x^3,4*x^4,5*x^5] sage: v[3] 3*x^3 sage: v[0] 0 sage: v[10] Traceback (most recent call last): ... IndexError: n = (10) must be between 0 and 5
self) |
sage: v = maxima('create_list(i*x^i,i,0,5)') sage: list(v) [0, x, 2*x^2, 3*x^3, 4*x^4, 5*x^5]
self) |
Return the length of a list.
sage: v = maxima('create_list(x^i,i,0,5)') sage: len(v) 6
self) |
Return print representation of this object.
sage: maxima('sqrt(2) + 1/3').__repr__() 'sqrt(2)+1/3'
self) |
Printing an object explicitly gives ASCII art:
sage: f = maxima('1/(x-1)^3'); f 1/(x-1)^3 sage: print f 1 -------- 3 (x - 1)
self, C) |
sage: CDF(maxima('sqrt(2)+1')) 2.41421356237
self, C) |
sage: CC(maxima('1+%i')) 1.00000000000000 + 1.00000000000000*I sage: CC(maxima('2342.23482943872+234*%i')) 2342.23482943872 + 234.000000000000*I sage: ComplexField(10)(maxima('2342.23482943872+234*%i')) 2300. + 230.*I sage: ComplexField(200)(maxima('1+%i')) 1.0000000000000000000000000000000000000000000000000000000000 + 1.0000000000000000000000000000000000000000000000000000000000*I sage: ComplexField(200)(maxima('sqrt(-2)')) 1.4142135623730950488016887242096980785696718753769480731767*I sage: N(sqrt(-2), 200) 1.4142135623730950488016887242096980785696718753769480731767*I
self) |
Return Latex representation of this Maxima object.
This calls the tex command in Maxima, then does a little ` post-processing to fix bugs in the resulting Maxima output.
sage: maxima('sqrt(2) + 1/3 + asin(5)')._latex_() '\sin^{-1}\cdot5+\sqrt{2}+{{1}\over{3}}'
self, R) |
If self is a Maxima matrix, return the corresponding Sage
matrix over the Sage ring
.
This may or may not work depending in how complicated the
entries of self are! It only works if the entries of self
can be coerced as strings to produce meaningful elements
of
.
sage: _ = maxima.eval("f[i,j] := i/j") sage: A = maxima('genmatrix(f,4,4)'); A matrix([1,1/2,1/3,1/4],[2,1,2/3,1/2],[3,3/2,1,3/4],[4,2,4/3,1]) sage: A._matrix_(QQ) [ 1 1/2 1/3 1/4] [ 2 1 2/3 1/2] [ 3 3/2 1 3/4] [ 4 2 4/3 1]
You can also use the matrix
command (which is defined
in sage.misc.functional
):
sage: matrix(QQ, A) [ 1 1/2 1/3 1/4] [ 2 1 2/3 1/2] [ 3 3/2 1 3/4] [ 4 2 4/3 1]
self, R) |
sage: RealField(100)(maxima('sqrt(2)+1')) 2.4142135623730950488016887242
self, R) |
sage: RDF(maxima('sqrt(2)+1')) 2.41421356237
self) |
Attempt to make a native Sage object out of this maxima object. This is useful for automatic coercions in addition to other things.
sage: a = maxima('sqrt(2) + 2.5'); a sqrt(2)+2.5 sage: b = a._sage_(); b sqrt(2) + 2.50000000000000 sage: type(b) <class 'sage.calculus.calculus.SymbolicArithmetic'>
We illustrate an automatic coercion:
sage: c = b + sqrt(3); c sqrt(3) + sqrt(2) + 2.50000000000000 sage: type(c) <class 'sage.calculus.calculus.SymbolicArithmetic'> sage: d = sqrt(3) + b; d sqrt(3) + sqrt(2) + 2.50000000000000 sage: type(d) <class 'sage.calculus.calculus.SymbolicArithmetic'>
Class: MaximaExpectFunction
Special Functions: _sage_doc_
Class: MaximaFunction
self, parent, name, defn, args, latex) |
Functions: integral,
integrate
Special Functions: __call__,
__init__,
__reduce__,
__repr__,
_latex_
Class: MaximaFunctionElement
Special Functions: _sage_doc_
See About this document... for information on suggesting changes.