📜 ⬆️ ⬇️

Maxima - Tips & Tricks, or collect crumbs of info on how to work on it

Human memory is a mystery to me. Being the owner of a weak memory since childhood, I always forget about some of the nuances of the world around me. However, this data should be at hand. And when there is not enough notebook, text files come to the rescue. One of these files contains a small assembly of daily and everyday Maxim commands.

I think all of us know this computer algebra system. She is not a competitor to Wolfram Mathematica , but she has exactly the functionality that I require from mathematical software. If it is easier and more accessible, you can count on everything, from sticks to supercomputers, and not always the tasks of engineering practice are transferred entirely from paper to program code. One example, which I honestly barely found, is the now-forgotten hack of our conversion production — an all-metal household vacuum civilian thermos, which was previously produced in the USSR in the Urals. In order to establish its production institute, in which I study, I de facto manually calculated all the necessary parameters of the working equipment on calculating machines. Therefore, a license for Mathematica is not an indicator or qualification to practice. Consider, I repeat, you can on everything.

From words to deeds. Below are divided into categories those moments in the Maxima documentation that you want to know for a novice user of this SKA.

')

General functionality


** or ^ - exponentiation;
% - the last cell of the output;
_ - the last input cell;
% th (n) - returns the nth output cell from the end;
$ - killing output;
kill (all) - clear the session;
describe (name) or? name - help for specific words;
example (name) is an example of use;
demo () - executes programs from the demonstration files supplied with the system;
'expression - prevents the expression from being evaluated;
'' expression - analog ev (forced evaluation of the expression);
num (%) is the numerator of the fraction;
denom (%) is the denominator of the fraction;
coeff (n, x, 3) - returns the coefficient for a variable to a given degree;
depends ([m, y], [x, z]) - sets the dependence m (x, z) and y (x, z);
second (y = 14) - will extract 14;
subst - substitution of one expression into another;
changevar (%, x - 3 - y, y, x); - replacement of variables in the expression;
%, y = x-3 - reverse substitution;
float (%) - convert to real form;
nouns (%) - reveals in general all imperfect forms - including derivatives;
eval - on the contrary, performs an additional one more calculation process. expressions may also include some characters that may also have their own values; and such a chain of “nested values” can go on as deeply as desired. One ev function call (without the eval option) is dropped one level down this chain: noeval blocks the computation stage itself; those. it can be used to apply other options of the ev function to an expression without recalculating it;
lhs (eq) - rhs (eq) - the left and right sides of some expression;
eliminate ([x + y + z = 1, x + y = 2, x + z = 3], [z]) - exclude a variable or several variables from the system of equations, that is, reduce the dimension of the system;
gcd (420,1176) - GCD;
mod (x, y) is the remainder of dividing x by y with x;
signum (x) - returns +1 if x> 0, -1 if x <0;
max / min;
log (x) is the NATURAL logarithm (“ln (x)”);
floor (4.445) - round down;
ceiling (4.445) - rounding up;
listofvars (%) turns the original expression into a list of variables contained in it;
numer: true (or numeric: true) - performing floating point calculations only, not with rational numbers;
bindtest - prohibits the use of a symbol in expressions before assigning it a value;
batch () loads the Maxima file with the .mac or .mc extension (from the original program name - Macsyma) and executes the expressions contained in it.
batchload () loads the batch file "silently": all functions and variables assigned to it become available, but the results are not visible, and all stored I / O, including the values ​​of the% and _ symbols and the results returned by the% th () function, remains the same as before the call.
file_search_maxima - a variable containing directories of user files and files of the SKA itself;
~ / .maxima - standard system directory;
file_search_lisp and file_search_demo are functions for searching for matching files;
load () - a wrapper over the two file loading functions, just shorter;
loadfile () - loads the file with Lisp source code (pair to save ());
stringout () - uploads any expressions and Maxima functions to the file;
declare () - insert a fact into the fact base;
facts (name) or facts () - find out the current state of the database;
remove () - remove properties from the database;
assume () - as arguments takes in any number the most ordinary equalities and inequalities in logical form, that is, not “a = b”, “a # b”, but “equal (a, b)”, “not equal (a , b) ". It is also possible to use from logical operators and (essentially assume (x> 0 and x <1) is the same as assume (x> 0, x <1)), but not or - the fact base does not support information of the form “ or"; and it's not about syntax, but about constructions, that is, expressions of the type not (a> b and a <c) are also unacceptable. Facts added by assume () also show the facts () functions:

Derivatives, limits, series ...


diff (expression) - finds the total differential of the expression, which is the sum of all partial derivatives with respect to expression variables;
diff (expression, variable) - finds the partial derivative of the first order;
diff (expression, variable, N) - finds the partial derivative of the Nth order;
diff (expression, x_1, N_1, x_2, N_2, ...) finds the sum of the partial derivatives;
derivlist (x, y, ..., v) - derivatives with respect to variables specified as arguments, as well as full differentials (since they do not depend on any variables);
integrate (%, x) - integration;
romberg (cos (sin (x + 1)), x, 0, 1) - numerical integration using the Romberg method;
limit ((x ^ 2 - 1) / (x ^ 2 + 1), x, inf) - calculation of limits;
limit ((x ^ 2 - 1) / (x ^ 2 + 1), x, minf);
limit (tan (x), x,% pi / 2, plus) - limit to the right;
limit (tan (x), x,% pi / 2, minus) - on the left;
tlimit (...) - attempt to find the limit with the tlimswitch flag raised (see below);
sum (i, i, 1, 100) is the sum of the series;
product - product of a series (syntax is similar to sum);
sum (1 / x ^ 2, x, 1, inf), simpsum = true; - to perform the summation, you must specify the option "simpsum = true";
sumcontract (sum1 + sum2) - the reduction of the sum;
taylor (sin (x), x, 0, 8) - rows;
niceindices (powerseries (sin (x), x, 0)) - rows with simplification;

Simplify


simp: false - disable forced simplification "on the fly";
ratdenomdivide - the default system variable is true. In this case, each fraction in which the numerator is a sum is decomposed into a sum of fractions with the same denominator. If we set this option to “false”, then all fractions with the same denominator will be combined into one fraction with the numerator as the sum of the numerators of the initial fractions;
expand () - expand parentheses, simplify;
distrib () - expand (), but only one level deep;
combine () is a function that combines fractions with the same denominators;
trigsimp (%) - trigonometric simplifications through the main trigonometric identity;
trigrat (%) - likewise, stronger;
trigredue (%) - transform trigonometric expressions into canonical finite trigonometric series (Fourier sums) [transforms the trigonometric expression as the sum of terms, each of which contains one sine or cosine];
trigexpand (%) - "opens" the arguments of trigonometric functions, according to the rules of trigonometric functions of the sum of the angles;
partfrac (%) - decomposition into simple fractions;
ratsimp (%) - quickly simplify the sum of rational expressions;
fullratsimp (expression) - sequentially applies the ratsimp function to the expression, as well as some irrational transformations and repeats these actions in a loop until the expression stops changing in the conversion process (slower, but gives a more reliable result);
ratexpand (%) - leads fractions to a common denominator;
radcan (%) - “reduce” exponents with logarithms by going to the canonical radical [simplifying exponential, logarithmic and power (with rational powers) functions];
factor - maximally collapses the expression in brackets;
factorsum () - if the polynomial cannot be represented as a product of several factors, you can try to convert it to the sum of such products;
0. Also there are such functions as: atensimp, foursimp, fullratsimp, logarc, rootscontract, scsimp, simplify_sum, vectorsimp.
1. After the ratexpand () and in the numerator and denominator of the fraction all brackets will be opened, in the case of rat () the terms, where there are, for example, two variables, will be grouped, and one of them will be put out of brackets.
2. expand expands the parentheses at all levels of nesting, and ratexpand opens a rational expression of only the first level, while subexpressions that are not rational are not processed;
3. ratexpand leads to fractional terms to a common denominator, and expand it does not;
4. The expand does not affect the system option ratdenomdivide;
5. expand does not convert the final decimal notation into rational numbers regardless of the value of the keepfloat system option.
6. maxposex and maxnegex are the variables that control the expansion to an integer degree — the maximum positive and negative exponent that will be expanded by this expand function (Default 1000) can be reassigned directly in the expand () function;
7. expop and expon are variables that set the maximum positive and negative degrees, which will be opened automatically, without calling the functions of the expand group (default is 0, that is, the degrees are not automatically expanded at all);
8. Flag - halfangles - controls the disclosure of half-angle formulas;
Two flags - trigexpandplus and trigexpandtimes - are respectively responsible for the use of the formulas for the sum of angles and multiple angles (set by default);
9. Flags trigsign and triginverses - the first one takes on the traditional two values ​​(true by default) and controls the removal of the sign beyond the trigonometric function. The triginverses flag is three-digit, and its default value is all. He is responsible for processing combinations of the form sin (asin (x)) or atan (tan (x)). The value of all allows you to open these combinations in both directions (I remind you that while some of the roots will be lost); true value only allows disclosure of the form of sin (asin (x)), that is, blocks the variant with loss of periodic values; a false case denies both directions of transformation;
10. Flag tlimswitch. By default, it is also disabled, and if it is turned on, the limit function will, if it is impossible to find the limit in other ways, try to find it by expanding the subliminal function into a Taylor series in a neighborhood of a given point;
11. The only flag directly related to the diff function itself is the derivabbrev flag, which affects the display of derivatives in Maxima output cells. By default, it is false, and derivatives are denoted as fractions with the letter d; if it is set to true, the derivatives will be displayed in abbreviated form, with the differentiation variables recorded as indices.
12. solveradcan - the flag, defaults to false, and setting this flag to true, we force solve to use radcan, which in some cases can help solve problems that without this key will make it impossible to find the exact solution.

Matrices


A: matrix ([1,2], [3,4]);
The determinant of the matrix. The determinant (matrix) function.
Transpose the matrix. The transpose (matrix) function.
Inverse matrix calculation. Function invert (matrix).
Construction of the characteristic polynomial of a matrix. Function charpoly (matrix, var).
Addition of matrices (“+” sign). Terminally adds all the elements of the two matrices.
Subtraction (the sign "-"). It is completely analogous to addition, but the elements of the matrices are subtracted.
Matrix division (“/” sign). The division is slightly different from addition, each element of one matrix is ​​divided by the corresponding element of another matrix.
Multiplication of matrices by term (sign "*"). This operator works the same way as addition: the elements of the first matrix are multiplied by the corresponding elements of the second matrix. This is not the multiplication of the matrix, which is usually implied in the course of linear algebra!
Multiplication of matrices (sign ".", Point).
addcol (V1, [9,10]) —adds a column to the matrix;
addrow (V1, [9,10]) - add a row to the matrix;
V1: submatrix (V1, 6,7) - remove the 6th and 7th column from the V1 matrix;
submatrix (the starting number of the line to be deleted, the ending number of the line to be deleted; Name
matrices;) - reducing the number of rows;
M [j, i] - references to a specific element of the array M;
zeromatrix (m, n) - creating a zero matrix of dimension m * n;
ident (n) - creating a unit square matrix;
diagmatrix (n, x) - creation of a diagonal square matrix of dimension n * n;
transpose (M) - transpose the matrix M;
matrix_size (M) - determining the number of columns and rows of the matrix;
rank (M) - determination of the rank of the matrix;
mattrace (M) - definition of the trace (the sum of the diagonal elements) of the square matrix (* the application is preceded by loading the package for working with matrices: load ("nchrpl"));
determinant (M) - calculation of the determinant (determinant) of a square matrix;
invert (M) is the calculation of the matrix inverse to M.

Ordinary Differential Equations


one)
ode2 (equation, function, variable). The function is usually y, and the variable is x;
In addition to solving a differential equation in general form, one can solve equations with initial conditions (boundary value problem). To do this, it is necessary to solve the equation in general form using the function code2, and then use one of the search functions for the initial conditions:
ic1 (solution, point x, value y at point x) —for solving first-order differential equations with an initial condition;
ic2 (solution, point x, value y at point x, value y 'at point x) - for solving second-order differential equations with an initial condition;
bc2 (solution, point x1, value y at point x1, point x2, value y at point x2) - for solving second-order differential equations with initial conditions in the form of two points;
2)
desolve (differential equation, variable);
If the system of differential equations is solved or there are several variables, then the equation and / or variables are presented in the form of a list:
desolve ([list of equations], [variable1, variable2, ...]);
As for the previous version, the diff function is used to denote derivatives in differential equations, which has the form 'diff (f (x), x);
atvalue (function, variable = point, value at point) - initial values.

Charts


plot2d (sin (x), [x, 0.6]);
plot2d (sin (x), [x, 0.1], [y, 0.1]);
plot2d ([parametric, realpart (W (% i * t)), imagpart (W (% i * t))], [t, 0,100], [nticks, 1000]) $
Parametric graphics are built like this:
[parametric, x (t), y (t)]. Therefore, parametric functions were substituted from the above formula. Further, [t, 0,100] is the range of points in which to draw the hodograph. Here each turns out differently, it is clear that the curve goes either to 0 or to infinity, the main thing here is not to overdo it. It is recommended to play around with the range of t values ​​in order to determine from where and where the curve is moving. This example starts at point [-1, 0] and goes to [0, 0]. [nticks, 1000] - this parameter sets the number of points for interpolation of the graph. The more of them there are, the smoother the schedule will look and the longer it will take to build it.
Charts in polar coordinates - the function draw2d is used with the following arguments:
user_preamble = “set grid polar”, // construction in polar coordinates;
nticks = n, // n is the number of points;
xrange = [dx1, dx2], // range of change x;
yrange = [dy1, dy2], // range of change y;
color = red, // color;
line_width = k, // width of the line that is used to build the graph;
title = "general name of the graphic",
polar (function, variable, lower_variable _, upper_limit_variable) // function of plotting;
The first and last function arguments are required. The first one initiates the construction of the graph in polar coordinates, the last (polar) is the function by which the graph is plotted.
plot3d (((x - 10) / 5) * ((y - 10) / 5), [x, 0.20], [y, 0.20]) - three-dimensional (3D) graphics;
Editing three-dimensional graphics is the same as two-dimensional.
The three-dimensional surface can be replaced by a gradient color transition. To do this, use the option "set view map".

Programming (more info in documentation)


for, while, until, etc.
Examples:
for i in s do
for k: 1 thru b: 3 do
for variable: start step thru step end do expression
for variable: start step step while condition do expression
for variable: start step step unless condition do expression
Function setting:
f1 (x, y): = x + y;

_- ============================= -_
########## OTHER #############
. ================================.

Russian designation - in Maxima:
arccos - acos
arcsin - asin
arctg - atan
ch - cosh
sh - sinh
ctg - cot
ln - log
tg - tan

Greek characters:
Gamma; Theta; Psi, etc.

Data processing:
one)
load (descriptive) $ / * load extension * /
a: [1,2,3,4];
mean (a); / * = 5/2 average * /
var (a); / * = 5/4 dispersion * /
std (a); / * =? 5/2 standard deviation * /
mean (arithmetic mean);
median (median);
variance (dispersion);
deviation (standard deviation);
2)
a: [1.0,2.0,3.0,4.0];
for i in a do ldisp (sin (i) / i);

Calculation of derivatives for all variables included in the expression:
eq: x * l / k; / * source expression * /
res: 0 for i in listofvars (eq) do res: res + (diff (eq, i) * concat ("d", (i))) ^ 2 $

For greater accuracy, there is a special function bfloat () (big float, large float), as well as the variable ffprec - for the number of decimal places. That is, to increase / decrease the accuracy, you need to assign a different numeric value to the fpprec variable and use the bfloat () function instead of float (). It is necessary that the variable numer be false.

By default, Maxima works in the MKS system: meter-kilogram-second:
2 * m;
2 * cm;
setunits ([centigram, inch, minute]) - the arguments of which are three basic units of measure: weight, length, and time;
setunits ([kg, m, s]);
convert (inch, [sm]); - conversion of units;

stringout ("/ Users / myusername / file1maxima.mc", INPUT);
To save all your input, you can be replayed later.

batch ("/ Users / myusername / file1maxima.mc");
If you have the exact numbering of the original calculation, it will not be necessary to load it.

SIMPSUM: TRUE;
sum (k, k, 1, n), simpsum;
=> \ displaystyle {{n ^ 2 + n} \ over {2}}
product (1 / (n ^ 2), n, 1,10); Products work in much the same way.

niceindices (powerseries (% e ^ ​​x, x, 0));
=> \ displaystyle \ sum_ {i = 0} ^ {\ infty} {{{x ^ {i}} \ over {i!}}}

taylor (% e ^ ​​x, x, 0, 5);
=> \ displaystyle 1 + x + {{x ^ 2} \ over {2}} + {{x ^ 3} \ over {6} + {{x ^ 4} \ over {24} + {{x ^ 5} \ over {120}} + \ cdots
trunc (%); Since it has been selected as the output of the polynomial.

load ("newton");
=> / sw / share / maxima / 5.9.0rc3 / share / numeric / newton.mac
newton (x ^ 7-5 * x ^ 6 + 4 * x ^ 4-5 * x ^ 2 + x + 2,1);
=> 8.194213634964119B-1

tex (%) - convert the expression to the form TeX;
$$ \ left (x + 1 \ right) ^ 2 $$

Convert TeX to PDF:
1. Paste the following five lines verbatim into the text editor:
\ documentclass {article}
\ pagestyle {empty}
\ begin {document}
\ huge
\ end {document}
2. Copy the tex () output line, and paste it between the \ huge and \ end {document} lines.
3. Save the result in my text format as: myoutput.txt
4. In the terminal window, navigate to the directory where you saved myoutput.txt
5. type:
pdflatex myoutput.txt
6. Hit return - a PDF file called myoutput.pdf containing your typeset equation.

load (to_poly_solve); - additional procedures for solving systems of algebraic equations;
to_poly_solve ([3 * z1 + z2 + 2 = 0, sqrt (z1) = z2], [z1, z2]);

sol: rk ([rk1, rk2, gamma, w], [gamma, w, fi, tetta], [0,% pi / 8,% pi / 2, 0], [t, 0, Tmax with_stdout ("gamma .txt ", for k: 1 thru points do print (sol [k] [1], sol [k] [2])) - an example of entering data from a file.

And now we will consider a typical example of using Maxima in student life. Beautifully and interestingly, this process was shown in an article on Habré earlier. I, in turn, will only turn the coordinate axes in one equation:
F:uxx+2*uxy+cos(x)^2*uyy-ctg(x)*(ux+uy); /* */ A:F,uxx=uxx,uxy=0,uyy=0,ux=0,uy=0$ A:A/uxx$ B:F,uxx=0,uxy=uxy,uyy=0,ux=0,uy=0$ B:B/(2*uxy)$ C:F,uxx=0,uxy=0,uyy=uyy,ux=0,uy=0$ C:C/(uyy)$ D:F,uxx=0,uxy=0,uyy=0,ux=ux,uy=0$ D:D/(ux)$ E:F,uxx=0,uxy=0,uyy=0,ux=0,uy=uy$ E:E/(uy)$ print("A = ",A)$ print("B = ",B)$ print("C = ",C)$ print("D = ",D)$ print("E = ",E)$ delta:B^2-A*C$ print("Delta = ", delta)$ /*   ,   > 0,       */ A*'diff(y,x,1)^2-2*B*'diff(y,x,1)+C=0; 'diff(y,x,1)=(2*B+sqrt((2*B)^2-4*A*C))/(2*A); ode2(%,y,x); solve(%,%c)$ w1:rhs(%[1])$ print("w1 = ",w1)$ 'diff(y,x,1)=(2*B-sqrt((2*B)^2-4*A*C))/(2*A); ode2(%,y,x); solve(%,%c)$ w2:rhs(%[1])$ print("w2 = ",w2)$ ux:un*diff(w2,x)+ue*diff(w1,x); uy:un*diff(w2,y)+ue*diff(w1,y); uxx:un*diff(diff(w2,x),x)+unn*diff(w2,x)^2+2*uen*diff(w1,x)*diff(w2,x)+ue*diff(diff(w1,x),x)+uee*diff(w1,x)^2; uxy:un*diff(diff(w2,x),y)+uen*(diff(w1,x)*diff(w2,y)+diff(w1,y)*diff(w2,x))+unn*diff(w2,x)*diff(w2,y)+ue*diff(diff(w1,x),y)+uee* diff(w1,x)*diff(w1,y); uyy:un*diff(diff(w2,y),y)+unn*diff(w2,y)^2+2*uen*diff(w1,y)*diff(w2,y)+ue*diff(diff(w1,y),y)+uee*diff(w1,y)^2; uy*E+ux*D+uyy*C+2*uxy*B+uxx*A; %,ctg(x)=cos(x)/sin(x); trigrat(%); 

Result:
2 * uen * cos (2 * x) -2 * uen

Source: https://habr.com/ru/post/238347/


All Articles