/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 12.04.0 ] */ /* [wxMaxima: comment start ] You can do some interesting sums in closed form using the sum function and the "simpsum" suffix modifier. First, let's add 5 to itself N times [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sum(5, i, 1, N); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Now add the integers from 1 to N. Use simpsum to make a closed form expression. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sum(i, i, 1, N); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ %, simpsum; %, factor; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's do more complicated sums [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sum(i^2, i, 1, N), simpsum, factor; sum(i^3, i, 1, N), simpsum, factor; sum(i^4, i, 1, N), simpsum, factor; sum(2*i-1, i, 1, N), simpsum, factor; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ sum(exp(i*x), i, 0, N), simpsum; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ sum(sin(i*x), i, 0, 4), trigexpand, factor; %, trigreduce, factor; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's do some interesting sums with inverse powers of integers. This is the definition of the Riemann zeta function! Note how even powers give closed form expressions. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ sum(1/i^2, i, 1, inf), simpsum; sum(1/i^3, i, 1, inf), simpsum; sum(1/i^4, i, 1, inf), simpsum; sum(1/i^5, i, 1, inf), simpsum; sum(1/i^6, i, 1, inf), simpsum; sum(1/i^12, i, 1, inf), simpsum; /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Numerical integration is necessary for functions that do not have a closed form integrand. We use the romberg method (successively halving the interval size). First check an integral we already know and compare the answer to the exact one. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ integrate(sin(x)^2, x, -%pi, %pi); romberg(sin(x)^2, x, -%pi, %pi); % - float(%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ romberg(exp(-x), x, 0, 1); % - float(1-1/%e); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Change tolerance for convergence to increase accuracy. The romberg algorithm converges whenever 1. absolute difference in successive iterations <= rombergabs OR 2. relative difference in successive iterations <= rombergtol OR 3. The number of iterations = rombergit Because of floating point accuracy you don't want to make the tolerances too small because convergence might become impossible. [wxMaxima: comment end ] */ /* [wxMaxima: comment start ] Default values for rombergabs, rombergtol, rombergit. Since rombergabs is 0 by default, only rombergabs and rombergit are used to determine convergence. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ float([rombergabs, rombergtol, rombergit]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Change the relative tolerance and do the integrals again. Note the improved accuracies. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ rombergtol : 1.e-8; /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ romberg(sin(x)^2, x, -%pi, %pi); % - float(%pi); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ romberg(exp(-x), x, 0, 1); % - float(1-1/%e); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's try plotting some functions. For this we need wxplot2d. First, let's plot sin(x) from 0 - 4*pi [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d(sin(x),[x,0,4*%pi]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] To plot more than 1 function, we use a list of expressions as the first argument rather than just an expression. Colors are assigned by default. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([sin(x)/x, x^2*exp(-x), 0.5*cos(x)^2], [x, 0, 10]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Same thing, but one can also control the colors of the three plots. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([sin(x)/x, x^2*exp(-x), 0.5*cos(x)^2], [x, 0, 10], [color,black,red,green]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can also specify the vertical range with a y range [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([sin(x)/x, x^2*exp(-x), 0.5*cos(x)^2], [x, 0, 10], [y, -1, 2]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can also make parametric plots with the parametric keyword. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([parametric,sin(t),sin(2*t), [t,0,2*%pi]]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] The default number of points is too small in parametric plots. Use the nticks variable to increase the number of points for better smoothness. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([parametric,sin(t),sin(2*t), [t,0,2*%pi]], [nticks,100]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] You can increase the thickness of the line with styles. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot2d([parametric,sin(t),sin(2*t), [t,0,2*%pi]], [nticks,100], [style,[lines,3]]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ wxplot2d([sin(x)/x, x^2*exp(-x), 0.5*cos(x)^2], [x, 0, 10], [y, -1, 2], [style,[lines,2]]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Let's make a 3-D plot, where color is proportional to z value. Default grid is 30 x 30. Default view is from angle angle (elevation = 60 degrees, azimuth = 30 degrees) [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot3d(1/(1+x^2+y^2), [x,-3,3], [y,-3,3])$ /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Make a high resolution grid 100 x 100 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot3d(1/(1+x^2+y^2), [x,-3,3], [y,-3,3], [grid,100,100]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] We can turn off the color palette. We also increase the plot size to 800 x 600 pixels. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot_size: [800,600]; wxplot3d(1/(1+x^2+y^2), [x,-3,3], [y,-3,3], [grid,100,100], [palette,false]); /* [wxMaxima: input end ] */ /* [wxMaxima: comment start ] Look at plot from on top so that z axis is not visible and color becomes the only clue for z value. We do this by changing both the elevation and azimuth variables to 0 (i.e., plot seen from above). I also add labels to the x and y axes and added a legend. Unfortunately, the elevation, azimuth and mesh_lines_color settings have no effect here. [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ wxplot3d(1/(1+x^2+y^2), [x,-3,3], [y,-3,3], [elevation,0], [azimuth,0], [mesh_lines_color,false], [grid,100,100], [xlabel, "x values"], [ylabel, "y values"], [legend,"Lorentzian curve"]); /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$