/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 12.04.0 ] */ /* [wxMaxima: comment start ] Derivatives are easy: diff(f, x, n) arg1 is expression or function arg2 is the variable arg3 is the order of the derivative (defaults to 1 if missing) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ diff(x^5, x); diff(x^5, x, 2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ ff(x) := sin(x)^2; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ diff(ff(x), x); diff(ff(x), x, 5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ trigreduce(%); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Multiple partial derivatives have same notation, with each variable followed by its order. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ g(x,y) := sin(x)^2 * (x^2+y^2)^2; diff1 : diff(g(x,y), x, 2, y, 1); diff2 : diff(g(x,y), y, 1, x, 2); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] is(exp1 = exp2) returns true if two expressions are the same, false otherwise. The below expression verifies that partial derivatives evaluated in opposite order are identical. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ is(diff1 = diff2); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Take the nth derivative of exp(-x^2/2). The term in () is proportional to the nth order Hermite polynomial (within factor of -1). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ diff(exp(-x^2), x, 10); %, factor; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ hermite(10,x); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We can also calculate Legendre polynomials directly from the derivative [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ 1/2^10/10! * diff( (x^2-1)^10, x, 10), factor; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Compare this answer to stored Legendre function legendre_p(n,x) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ legendre_p(10,x), expand, factor; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Integration is easy, too. You can do definite and indefinite integrals. Definite integrals require two limits. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ integrate(x^2, x); integrate(x^2, x, 0, 2); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ integrate(x^2*exp(-5*x), x); integrate(x^2*exp(-5*x), x, 0, inf); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Other interesting integrals can be readily evaluated. Use inf for infinity and -inf or minf for -infinity [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ integrate(exp(-x^2), x, -inf, inf); integrate(x^2 * exp(-x^2), x, -inf, inf); integrate(sin(x)/x, x, minf, inf); integrate(1 / (x^2 + 4), x, minf, inf); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Expressions with unspecified constants have to be done carefully because wxMaxima sometimes needs to know whether the constant is real, positive, integer, etc. Parameters default to being real, but noninteger. Here's a dialog where an integral is requested and the user is asked to respond to questions about parameter. The second integral has two questions. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ integrate(exp(-a*x^2), x, -inf, inf); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ integrate(1/(x^2+a^2), x, -inf, inf); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Use the assume() function to specify these things. The arguments are called predicates and have the form a>0, b, >=, <, <=, equal() notequal(). Note that equal and notequal are functions taking two arguments. Uugghh... [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ assume(a>0, b>0, c>b, c>a, notequal(g,a), equal(b,e) ); integrate(exp(-a*x^2), x, -inf, inf); integrate(1/(x+b)^2, x, 0, inf); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] facts() lists all the assumptions you have specified [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ facts(); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] functions lists all the functions you have specified [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ functions; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] forget() tells wxmaxima to forget the specified assumptions, which are specified the same way as assume(). This allows you to make wxMaxima forget specific assumptions. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ forget(b < c, equal(b,e)); facts(); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ forget(a>0); facts(); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Use the is() function to test expressions [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ is(5>0); is(a^2 > 0); factor(x^2-y^2); is( equal((x^2-z^2) , ( (x-z)*(x+z) ) ) ); is(equal(x^2-y^2, -y^2+x^2) ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can declare a variable to be real, integer, complex, etc. New variables are assumed to be real when defined. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ declare(n, integer); sin(n*%pi); cos(n*%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now declare it to be noninteger [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ declare(m, noninteger); sin(m*%pi); cos(m*%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can calculate power series easily with the taylor function. Let's do a couple we already know [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ taylor(sin(x), x, 0, 5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ taylor(log(x), x, 1, 7); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now let's expand a function that would take a *long* time by hand [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ taylor(exp(sin(x)), x, 0, 13); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Check the accuracy of the series approximation. First make a function from the series. The construction ''(...) evaluates everything inside the (), and the := then assigns the expression to the function. If you write df(x) := taylor(f(x), x, a, n), you end up with a function set to taylor(...) which cannot be evaluated for constant arguments because the constant is substituted for the variable everywhere. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ expsin(x) := ''( taylor(exp(sin(x)), x, 0, 13) ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] It's much easier to define this function using define(). [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ define(expsin2(x), taylor(exp(sin(x)), x, 0, 13)); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Check that these functions are identical using is(exp1 = exp2). You can test many conditions this way, e.g. is(a < b), is(a > b), is(a # b) (i.e., not equal) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ is(expsin(x) = expsin2(x)); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Check the approximation against the exact value for x = 1.0 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ float( expsin(1.0) - exp(sin(1.0)) ); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's plot the function and the series approximation. A growing divergence is apparent for x > 1.5 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([expsin(x), exp(sin(x))], [x, 0, 2.5]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ float(expsin(2.0) - exp(sin(2.0))); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] taylor can handle Laurent series too [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ taylor(1/sin(x)^3, x, 0, 5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ taylor(1/log(x), x, 1, 4); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can kill the definition of some variables [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ a: 24; kill(a); a; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ ff(x) := x^2; b : 10; G : x^2 - x; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Get a list of all user defined functions, user defined values and user defined predicates [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ functions; values; facts(); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Kill selective user assignments [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(ff); kill(b); kill(n); functions; values; facts(); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Kill all user assignments with kill(all). Nothing is remembered. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ kill(all); ff(x); b; g; functions; values; facts(); /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$