Debian Codegraph @

texmf-dist/doc/latex/tkz-elements/TKZdoc-elements-maths.tex

raw
1 \newpage
2 \section{Maths tools}
3
4 The \tkzname{maths tools} module provides general-purpose mathematical functions for solving algebraic equations and linear systems. These tools serve as computational backbones for various geometric or algebraic operations in the \tkzNamePack{tkz-elements} library.
5
6 The key features include:
7 \begin{itemize}
8 \item Solving polynomial equations of degree 1, 2, or 3.
9 \item Solving linear systems via augmented matrix transformation.
10 \end{itemize}
11
12 These functions handle both symbolic and numerical workflows and are suitable for educational, demonstrative, or computational geometry contexts.
13
14
15 \subsection*{Functions overview}
16
17 \begin{center}
18 \bgroup
19 \catcode`_=12
20 \small
21 \captionof{table}{Math functions}
22 \begin{tabular}{ll}
23 \toprule
24 \textbf{Name} & \texttt{Reference} \\
25 \midrule
26 \tkzFct{tkz}{tkz.solve(...)} & \\
27 \midrule
28 \tkzFct{tkz}{tkz.solve\_linear\_system} & \\
29 \bottomrule
30 \end{tabular}
31 \egroup
32 \end{center}
33
34
35 \subsection{\tkzFct{tkz}{solve(...)}}
36 This general-purpose function solves polynomial equations of degree 1, 2, or 3 with real or complex coefficients. It delegates to specific solvers depending on the number of parameters.
37
38 \medskip
39 \texttt{Syntax: }
40
41
42 \begin{verbatim}
43 x = solve(a, b) -- solves ax + b = 0
44 x1, x2 = solve(a, b, c) -- solves ax^2 + bx + c = 0
45 x1, x2, x3 = solve(a, b, c, d) -- solves ax^3 + bx^2 + cx + d = 0
46 \end{verbatim}
47
48 \medskip
49 \texttt{Arguments: }
50
51 \begin{itemize}
52 \item 2 parameters: $a$, $b$ — coefficients of a linear equation $ax + b = 0$.
53 \item 3 parameters: $a$, $b$, $c$ — coefficients of a quadratic equation.
54 \item 4 parameters: $a$, $b$, $c$, $d$ — coefficients of a cubic equation.
55 \end{itemize}
56
57 \medskip
58 \texttt{Return: }
59
60 Depending on the degree of the equation:
61 \begin{itemize}
62 \item \code{solve(a,b)} returns one value (or an error if $a = 0$).
63 \item \code{solve(a,b,c)} returns two roots (real or \code{false} if complex and unsupported).
64 \item \code{solve(a,b,c,d)} returns up to three real roots (complex roots not currently supported).
65 \end{itemize}
66
67 \medskip
68 \texttt{Examples: }
69
70 \begin{verbatim}
71 x = solve(2, -4) -- x = 2
72 x1, x2 = solve(1, -3, 2) -- x1 = 2, x2 = 1
73 x1, x2, x3 = solve(1, -6, 11, -6) -- x1 = 1, x2 = 2, x3 = 3
74 \end{verbatim}
75
76 \medskip
77 \texttt{Notes: }
78
79 \begin{itemize}
80 \item For quadratics with complex solutions, the function currently returns \code{false, false}.
81 \item Cubic solving is limited to real roots using Cardano's method and assumes $a \ne 0$.
82 \item Internally uses the functions \code{tkz.solve\_quadratic} and \code{tkz.solve\_cubic}.
83 \end{itemize}
84
85 \subsection{Function \tkzFct{math}{solve\_linear\_system(M, N)}}
86 Solves the linear system $MX = N$ using Gauss–Jordan elimination on the augmented matrix $[M\|N]$.
87
88 \begin{itemize}
89 \item \texttt{M} is the coefficient matrix ($m \times n$).
90 \item \texttt{N} is the right-hand side column vector ($m \times 1$).
91 \item Returns the unique solution vector $X$ ($n \times 1$), if it exists.
92 \end{itemize}
93
94 \medskip
95 \texttt{Return value: }
96
97 \begin{itemize}
98 \item Returns a new \tkzClass{matrix} representing the solution.
99 \item Returns |nil| and an error message if:
100 \begin{itemize}
101 \item the system is inconsistent (no solution),
102 \item the system is underdetermined (infinite solutions),
103 \item dimensions are incompatible.
104 \end{itemize}
105 \end{itemize}
106
107 \texttt{Example usage: }
108
109 \begin{tkzexample}[code only]
110 M = matrix({{2,1}, {4,-6}})
111 N = matrix({{5}, {-2}})
112 X = solve_linear_system(M, N)
113 \end{tkzexample}
114 \endinput