<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>alchemmist — Math</title><link>https://alchemmist.xyz/tags/math/</link><description>Последние записи в блоге alchemmist</description><generator>Hugo 0.163.3</generator><language>en</language><atom:link href="https://alchemmist.xyz/tags/math/index.xml" rel="self" type="application/rss+xml"/><lastBuildDate>Sat, 13 Dec 2025 14:47:00 +0300</lastBuildDate><item><title>Probabilistic hypothesis testing</title><link>https://alchemmist.xyz/articles/probabilistic-hypothesis-testing/</link><pubDate>Sat, 13 Dec 2025 14:47:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/probabilistic-hypothesis-testing/</guid><description>We have a coin, with $p - \text{probability of 1 (head)}$ and $(1 - p) - \text{probability of 0 (tail)}$. We tossed it $n$ times and got a results: $n: x_1, x_2, \dots, x_n \in \{0, 1\}$. Our task it will be a checking the truth of hypothesis $H_0: p = 0.5$. If $H_0$ will be false, we need to choose alternative hypothesis $H_1: p \neq 0.5$.
Firstly, let’s make a little speculations, using our intuition. We, sure, if $\sum\limits_{i = 1}^{n}{x_i} = n$, that $H_0$ is false, because we haven’t reason for assume, that coin can be $0$, therefore $p = 1$. But, what about case, when we have $n = 20$ and $\sum{x_i} = 15$? In this case, we can’t be sure. Our questions, it’s, how to make a decision in such situations. In this decision we may make a one of two types of errors:</description><content:encoded><![CDATA[<p>We have a coin, with $p - \text{probability of 1 (head)}$ and $(1 - p) - \text{probability of 0 (tail)}$. We tossed it $n$ times and got a results: $n: x_1, x_2, \dots, x_n \in \{0, 1\}$. Our task it will be a checking the truth of hypothesis $H_0: p = 0.5$. If $H_0$ will be false, we need to choose alternative hypothesis $H_1: p \neq 0.5$.</p>
<p>Firstly, let’s make a little speculations, using our intuition. We, sure, if $\sum\limits_{i = 1}^{n}{x_i} = n$, that $H_0$ is false, because we haven’t reason for assume, that coin can be $0$, therefore $p = 1$. But, what about case, when we have $n = 20$ and $\sum{x_i} = 15$? In this case, we can’t be sure. Our questions, it’s, how to make a decision in such situations. In this decision we may make a one of two types of errors:
</p>
$$
\begin{align*}
&Type \ 1: \text{In actual fact }H_0\text{ is \textbf{true}, but we told is \textbf{false}.}\\
&Type \ 2: \text{In actual fact }H_0\text{ is \textbf{false}, but we told is \textbf{true}.}\\
\end{align*}
$$<p>
And in statistics our default predisposition it’s minimization errors of type 1. For example, if we made a medicine drug and after testing we checking $H_0$: “Our medicine drug is effective.”. If we make error of type 1, we will put broken drug to many peoples — it’s not good. In business, if make first type error we need to spend more many for new model. That’s the reason, for:
</p>
$$
P[Type 1] < \alpha, \quad \alpha \text{ — significance level}
$$<p>
For make this decision we need to compare $\sum{x_i}$ with $0.5n$. How big is difference? The theorem of Moivre–Laplace:
</p>
$$
\frac{\mu - nP}{\sqrt{np\cdot(1 - p)}} \sim \mathcal{N}(0, 1),\qquad \mu = \sum{x_i}
$$<p>
Let’s use it in our case:
</p>
$$
Z = \frac{\mu - 0.5n}{\sqrt{0.25n}} \sim \mathcal{N}(0, 1)
$$<p>
For example, if in real experiment we got $Z = 10$, that’s mean $H_0$ is <strong>very</strong> unlikely. So, we need to define the border $t$ for $Z$, after that we reject $H_0$:
<img
    src="/images/gaus-2_hu_f79d70c0a6f02165.webp"
    width="1600"
    height="512"
    class="content-img" style="width:500px"
    alt=""
    loading="lazy"
    decoding="async"
  />
We need to find the value of $t$, that probability of cross over it, is significance level $\alpha$.  If $|Z| > q_{1 - \frac{\alpha}{2}}$, we talk $H_1$ is truth and we reject $H_0$. Else, we approve $H_0$.</p>
<p>The interesting fact is first type of errors very easy for control. We can always say, that $H_0$ is truth. Then probability of errors type 1 will equal zero.</p>
]]></content:encoded><category>math</category></item><item><title>Welford algorithm</title><link>https://alchemmist.xyz/articles/welford-algorithm/</link><pubDate>Wed, 10 Sep 2025 17:31:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/welford-algorithm/</guid><description>Imagine that data is streaming to you: millions of transactions, stock prices, sensor readings. You need to calculate the mean, variance, and correlations. The classic way is to save all the data and then calculate it. But it takes up a lot of memory, calculations are getting heavy, rounding errors occur on large numbers. Recently, I came across to Welford algorithm, which can be online calculating in one iteration without save big data. It’s very elegant, stable and exact algorithm.</description><content:encoded><![CDATA[<p>Imagine that data is streaming to you: millions of transactions, stock prices, sensor readings. You need to calculate the mean, variance, and correlations. The classic way is to save all the data and then calculate it. But it takes up a lot of memory, calculations are getting heavy, rounding errors occur on large numbers. Recently, I came across to Welford algorithm, which can be online calculating in one iteration without save big data. It’s very elegant, stable and exact algorithm.</p>
<p>The problem settings is pretty simple: we want to calculate statistics (mean, variance, covariance, correlation) step by step, when we receive $n$ data in a stream, without saving all data and additional iteration. Let’s remind formulas on base way. Mean:
</p>
$$
\overline{x} = \frac{1}{n}\sum\limits_{i = 1}^{n}x_i
$$<p>
Variance:
</p>
$$
s^2 = \frac{1}{n - 1}\sum\limits_{i = 1}^{n}(x_i - \overline{x})^2
$$<p>
As you see for mean we need sum: first problem — how to get sum without all numbers? And for variance we need mean: second problem — how to know mean without all data?</p>

<h2 id="intuition-of-method">
  <a class="link" href="#intuition-of-method">
    #
  </a>
  Intuition of method
</h2>

<p>Let’s try to feel the intuition of Welford method. Imagine we have the dataset: $A = \{1, 2, 3\}$, mean of this dataset is $\overline{x}_A = \frac{1 + 2 +3}{3} = 2$ and then we got one more number: $6$. Do you feel it will be move our mean to the bigger side? But how much bigger? Imagine similar dataset but with more data: $B = \{1, 1, 2, 2, 3, 3\}$ the mean also is $2$ and we also adding number $6$. Again we fill it will be move to the bigger side, but no so strong. Let’s check our intuition:
</p>
$$
\begin{align*}
&A' = \{1, 2, 3, 6\}, \quad \overline{x}_{A'} = \frac{1 + 2 + 3 + 6}{4} = 3, \quad \Delta_A = |\overline{x}_A - \overline{x}_{A'}| = 1 \\
&B' = \{1, 1, 2, 2, 3, 3, 6\},  \quad \overline{x}_{B'} = \frac{2(1 + 2 + 3) + 6}{7} \approx 2.57, \quad \Delta_{B} = \overline{x}_B - \overline{x}_{B'} \approx 0.57
\end{align*}
$$<p>
Our intuition was right! It remains for us to figure out how we can calculate this delta, if we got only previous mean $\overline{x}_{i - 1}$, new number $x_i$ and count of our numbers. The Welford method told: every new value move mean in its own direction with weight $1/i$:
</p>
$$
\overline{x}_i = \overline{x}_{i - 1} + \frac{1}{i}(x_i - \overline{x}_{i - 1})
$$<p>
Let’s check it for $B$ dataset. We got mean without new number $\overline{x}_{i - 1} = 2$ and new number $x_i = 6$ and it’s a seventh number, $i = 7$. Goal is find a $\overline{x}_i$ mean with Welfod forumula:
</p>
$$
\overline{x}_i = 2 + \frac{1}{7}(6 - 2) = 2 + 0.57\ldotp\!\ldotp\!\ldotp \ \approx 2.57
$$<p>
It’s absolutely exact value, as you see. Nice!</p>

<h2 id="variance-correlation-covariance">
  <a class="link" href="#variance-correlation-covariance">
    #
  </a>
  Variance, correlation, covariance
</h2>

<p>The real power of Welford&rsquo;s algorithm reveals itself when calculating variance. The naive approach requires storing all data points and recalculating the mean before computing variance, which is computationally expensive. Welford&rsquo;s method elegantly solves this by maintaining a running estimate of variance using the following recurrence relation:</p>
<p>For variance, we maintain the current mean $\overline{x}$ and the sum of squares of differences $S$. For each new data point $x_n$ at step $n$:
</p>
$$
\begin{gather*}
\overline{x}_n = \overline{x}_{n-1} + \frac{1}{n}(x_n - \overline{x}_{n-1}) \\
S_n = S_{n-1} + (x_n - \overline{x}_{n-1})(x_n - \overline{x}_n)
\end{gather*}
$$<p>
The population variance can then be calculated as $\sigma^2 = S_n/n$, while the sample variance is $s^2 = S_n/(n-1)$.</p>
<p>This approach extends beautifully to covariance and correlation. For two variables $X$ and $Y$, we maintain counts $n$, means $\overline{x}$ and $\overline{y}$, and accumulated products $C_{xy}$:
</p>
$$
\begin{gather*}
\delta_x = x_n - \overline{x}_{n-1}, \quad
\delta_y = y_n - \overline{y}_{n-1} \\
\overline{x}_n = \overline{x}_{n-1} + \frac{\delta_x}{n}, \quad
\overline{y}_n = \overline{y}_{n-1} + \frac{\delta_y}{n} \\
C_{xy_n} = C_{xy_{n-1}} + \delta_x (y_n - \overline{y}_n) \\
\end{gather*}
$$<p>
The covariance is then $\text{cov}(X,Y) = \frac{C_{xy_n}}{(n-1)}$ and correlation is $\text{corr}(X,Y) = \frac{C_{xy_n}}{\sqrt{S_{x_n} S_{y_n}}}$.</p>

<h2 id="c-implementation">
  <a class="link" href="#c-implementation">
    #
  </a>
  C implementation
</h2>

<p>Here&rsquo;s a complete C implementation of Welford&rsquo;s algorithm for calculating mean and variance:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="cl"><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span></span></span><span class="line"><span class="cl"><span class="cp">#include</span> <span class="cpf">&lt;math.h&gt;</span><span class="cp">
</span></span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kt">long</span> <span class="kt">long</span> <span class="n">n</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">mean</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">M2</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span> <span class="n">welford_state</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">void</span> <span class="nf">welford_update</span><span class="p">(</span><span class="n">welford_state</span> <span class="o">*</span><span class="n">state</span><span class="p">,</span> <span class="kt">double</span> <span class="n">x</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span><span class="o">++</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">delta</span> <span class="o">=</span> <span class="n">x</span> <span class="o">-</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean</span> <span class="o">+=</span> <span class="n">delta</span> <span class="o">/</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">M2</span> <span class="o">+=</span> <span class="n">delta</span> <span class="o">*</span> <span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">double</span> <span class="nf">welford_mean</span><span class="p">(</span><span class="k">const</span> <span class="n">welford_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">double</span> <span class="nf">welford_variance</span><span class="p">(</span><span class="k">const</span> <span class="n">welford_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">?</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">M2</span> <span class="o">/</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">:</span> <span class="mf">0.0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">double</span> <span class="nf">welford_stddev</span><span class="p">(</span><span class="k">const</span> <span class="n">welford_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="nf">sqrt</span><span class="p">(</span><span class="nf">welford_variance</span><span class="p">(</span><span class="n">state</span><span class="p">));</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">welford_state</span> <span class="n">state</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">};</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">test_data</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">,</span> <span class="mf">6.0</span><span class="p">};</span>
</span></span><span class="line"><span class="cl">    <span class="kt">size_t</span> <span class="n">data_size</span> <span class="o">=</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">test_data</span><span class="p">)</span> <span class="o">/</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">test_data</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
</span></span><span class="line"><span class="cl">    
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="p">(</span><span class="kt">size_t</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">data_size</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nf">welford_update</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</span><span class="p">,</span> <span class="n">test_data</span><span class="p">[</span><span class="n">i</span><span class="p">]);</span>
</span></span><span class="line"><span class="cl">        <span class="nf">printf</span><span class="p">(</span><span class="s">&#34;Added %.1f: mean=%.3f, variance=%.3f, stddev=%.3f</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">               <span class="n">test_data</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="nf">welford_mean</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</span><span class="p">),</span> 
</span></span><span class="line"><span class="cl">               <span class="nf">welford_variance</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</span><span class="p">),</span> <span class="nf">welford_stddev</span><span class="p">(</span><span class="o">&amp;</span><span class="n">state</span><span class="p">));</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">    
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>For covariance and correlation, we can extend this approach:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-c" data-lang="c"><span class="line"><span class="cl"><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kt">long</span> <span class="kt">long</span> <span class="n">n</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">mean_x</span><span class="p">,</span> <span class="n">mean_y</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">C2</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span> <span class="n">welford_cov_state</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">void</span> <span class="nf">welford_cov_update</span><span class="p">(</span><span class="n">welford_cov_state</span> <span class="o">*</span><span class="n">state</span><span class="p">,</span> <span class="kt">double</span> <span class="n">x</span><span class="p">,</span> <span class="kt">double</span> <span class="n">y</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span><span class="o">++</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">delta_x</span> <span class="o">=</span> <span class="n">x</span> <span class="o">-</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean_x</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kt">double</span> <span class="n">delta_y</span> <span class="o">=</span> <span class="n">y</span> <span class="o">-</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean_y</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean_x</span> <span class="o">+=</span> <span class="n">delta_x</span> <span class="o">/</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean_y</span> <span class="o">+=</span> <span class="n">delta_y</span> <span class="o">/</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="n">state</span><span class="o">-&gt;</span><span class="n">C2</span> <span class="o">+=</span> <span class="n">delta_x</span> <span class="o">*</span> <span class="p">(</span><span class="n">y</span> <span class="o">-</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">mean_y</span><span class="p">);</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kt">double</span> <span class="nf">welford_covariance</span><span class="p">(</span><span class="k">const</span> <span class="n">welford_cov_state</span> <span class="o">*</span><span class="n">state</span><span class="p">)</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)</span> <span class="o">?</span> <span class="n">state</span><span class="o">-&gt;</span><span class="n">C2</span> <span class="o">/</span> <span class="p">(</span><span class="n">state</span><span class="o">-&gt;</span><span class="n">n</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">:</span> <span class="mf">0.0</span><span class="p">;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div>]]></content:encoded><category>algorithms</category><category>C</category><category>math</category></item><item><title>Gram-Schmidt orthogonalization</title><link>https://alchemmist.xyz/articles/gram-schmidt/</link><pubDate>Sun, 06 Jul 2025 07:16:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/gram-schmidt/</guid><description>In more practical cases we want to make projection of vector to subspace, and if subspace define with orthogonal and orthonormal basis we can do it easily. To orthogonalize a vectors, we using Gram-Schmidt method.
We have source vectors $v_1, v_2, \dots, v_n$, and we need to get orthogonal vectors $u_1, u_2, \dots, u_n$. In general, describe the method: 0. Remove all zero vector.
We take first vector unchanged: $u_1 = v_1$. Next vector find from $v_2$ and projections to last vectors: $u_2 = v_2 - \text{Proj}_{u_1}{v_2}$. Again: $u_3 = v_3 - \text{Proj}_{u_1}{v_3} - \text{Proj}_{u_2}{v_3}$. And continue it to $u_n$ vector: $u_n = v_n - \text{Proj}_{u_1}{v_n} - \text{Proj}_{u_2}{v_n} - \dots - \text{Proj}_{u_{n - 1}}{v_n}$. Let’s remind how to find projection: $\text{Proj}_{u}{v} = \frac{\langle u, v\rangle}{||u||^2}u$. If we want orthonormal basis we can product all vectors $u$ to $\frac{1}{||u_i||}$. Let’s see on example: $v_1 = \begin{pmatrix}1 \\ 1\end{pmatrix}, \ v_2 = \begin{pmatrix}1 \\ 0\end{pmatrix}$. Firstly set $u_1 = v_1$, then $u_2 = v_2 - \text{Proj}_{u_1}{v_2} = \begin{pmatrix}1 \\ 0\end{pmatrix} - \begin{pmatrix}0.5 \\ 0.5\end{pmatrix} = \begin{pmatrix}0.5 \\ -0.5\end{pmatrix}$. Finally we got orthogonal vectors $u_1 = \begin{pmatrix}1 \\ 0\end{pmatrix}$, $u_2 = \begin{pmatrix}0.5 \\ -0.5\end{pmatrix}$.</description><content:encoded><![CDATA[<p>In more practical cases we want to make projection of vector to subspace, and if subspace define with orthogonal and orthonormal basis we can do it easily. To orthogonalize a vectors, we using Gram-Schmidt method.</p>
<p>We have source vectors $v_1, v_2, \dots, v_n$, and we need to get orthogonal vectors $u_1, u_2, \dots, u_n$. In general, describe the method:
0. Remove all zero vector.</p>
<ol>
<li>We take first vector unchanged: $u_1 = v_1$.</li>
<li>Next vector find from $v_2$ and projections to last vectors: $u_2 = v_2 - \text{Proj}_{u_1}{v_2}$.</li>
<li>Again: $u_3 = v_3 - \text{Proj}_{u_1}{v_3} - \text{Proj}_{u_2}{v_3}$.</li>
<li>And continue it to $u_n$ vector: $u_n = v_n - \text{Proj}_{u_1}{v_n} - \text{Proj}_{u_2}{v_n} - \dots - \text{Proj}_{u_{n - 1}}{v_n}$.
Let&rsquo;s remind how to find projection: $\text{Proj}_{u}{v} = \frac{\langle u, v\rangle}{||u||^2}u$. If we want orthonormal basis we can product all vectors $u$ to $\frac{1}{||u_i||}$.</li>
</ol>
<p>Let’s see on example: $v_1 = \begin{pmatrix}1 \\ 1\end{pmatrix}, \ v_2 = \begin{pmatrix}1 \\ 0\end{pmatrix}$.
Firstly set $u_1 = v_1$, then $u_2 = v_2 - \text{Proj}_{u_1}{v_2} = \begin{pmatrix}1 \\ 0\end{pmatrix} - \begin{pmatrix}0.5 \\ 0.5\end{pmatrix} = \begin{pmatrix}0.5 \\ -0.5\end{pmatrix}$. Finally we got orthogonal vectors $u_1 = \begin{pmatrix}1 \\ 0\end{pmatrix}$, $u_2 = \begin{pmatrix}0.5 \\ -0.5\end{pmatrix}$.</p>
]]></content:encoded><category>math</category></item><item><title>Stationary points and Lagrange method</title><link>https://alchemmist.xyz/articles/stationary-points-and-lagrange/</link><pubDate>Sun, 06 Jul 2025 05:19:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/stationary-points-and-lagrange/</guid><description>When we analyze a function, we want to find stationary points. If we haven’t a constraints, use gradient. Gradient it’s a vector of partial derivatives:
$$ \nabla f = \begin{pmatrix} \displaystyle \frac{\partial f}{\partial x_1} \\ \displaystyle \frac{\partial f}{\partial x_2} \\ \dots \\ \displaystyle \frac{\partial f}{\partial x_n} \end{pmatrix} $$See on example: $f(x, y, z) = x^2 + y^2 - 4x - 4y + z^4 - 4z^2$. Let’s find gradient:
$$ \nabla f = \begin{pmatrix} \displaystyle \frac{\partial f}{\partial x} \\ \displaystyle \frac{\partial f}{\partial y} \\ \displaystyle \frac{\partial f}{\partial z} \end{pmatrix} = \begin{pmatrix} 2x - 4 \\ 2y - 4 \\ 4z^3 - 8z \end{pmatrix} $$Then set equal to zero: $\nabla f = 0$, and got system of equations:</description><content:encoded><![CDATA[<p>When we analyze a function, we want to find stationary points. If we haven’t a constraints, use gradient. Gradient it’s a vector of partial derivatives:</p>
$$
\nabla f = \begin{pmatrix}
\displaystyle \frac{\partial f}{\partial x_1} \\
\displaystyle \frac{\partial f}{\partial x_2} \\
\dots \\
\displaystyle \frac{\partial f}{\partial x_n}
\end{pmatrix}
$$<p>See on example: $f(x, y, z) = x^2 + y^2 - 4x - 4y + z^4 - 4z^2$. Let’s find gradient:</p>
$$
\nabla f = \begin{pmatrix}
\displaystyle \frac{\partial f}{\partial x} \\
\displaystyle \frac{\partial f}{\partial y} \\
\displaystyle \frac{\partial f}{\partial z}
\end{pmatrix} =  \begin{pmatrix}
2x - 4 \\
2y - 4 \\
4z^3 - 8z
\end{pmatrix}
$$<p>Then set equal to zero: $\nabla f = 0$, and got system of equations:</p>
$$
\begin{cases}2x - 4 = 0 \\ 2y - 4 = 0 \\ 4z^3 - 8z = 0 \end{cases} \quad \Rightarrow \quad \begin{cases}x = 2\\ y = 2 \\ \left[
\begin{array}{l}
z = 0 \\
z = \sqrt{2} \\
z = -\sqrt{2}
\end{array}
\right.\end{cases}
$$<p>Finally, we got this stationary points: $(2, 2, 0), \ (2, 2, \sqrt{2}), \ (2, 2, -\sqrt{2})$.</p>
<blockquote class="markdown-blockquote">
  <p>If you want to continue analysis, use <a href="/articles/hessian-matrix/">Hessian matrix</a>.</p>

</blockquote>
<p>Now, look at case, when we have function and <strong>constraints</strong>. This is where the <strong>Lagrange multiplier method</strong> comes into play. For example, function is $f(x, y) = x^2 + y^2$ on condition $x + y = 1$. Rewrite a condition as: $g(x, y) = 0$, therefore $g(x, y) = x + y - 1$. Then, find gradients for all functions:
</p>
$$
\nabla f = \begin{pmatrix}2x \\ 2y\end{pmatrix}, \quad \nabla g = \begin{pmatrix}1 \\ 1\end{pmatrix}
$$<p>
After that, write down the Lagrange equation and solve it. In general, Lagrange equation looks like:
</p>
$$
\begin{cases}
\displaystyle \frac{\partial f}{\partial x_1} = \lambda \frac{\partial g}{\partial x_1} \\
\displaystyle \frac{\partial f}{\partial x_2} = \lambda \frac{\partial g}{\partial x_2} \\
\quad \dots \\
\displaystyle \frac{\partial f}{\partial x_n} = \lambda \frac{\partial g}{\partial x_n} \\
g(x_1, x_2, \dots x_n) = 0
\end{cases}
$$<p>
In our case:
</p>
$$
\begin{cases}2x = \lambda \cdot 1\\2y = \lambda \cdot 1\\x + y = 1\end{cases} \quad \Rightarrow \quad \begin{cases}\lambda = 2x\\\lambda = 2y\\x + y = 1\end{cases} \quad \Rightarrow \quad \begin{cases}x = y\\2x = 1\end{cases}\quad \Rightarrow \quad x = y = \frac{1}{2}
$$<p>
Done! Stationary point is $\left(\frac{1}{2}, \frac{1}{2} \right)$. Let’s resume: if functions without constraints use equation $\nabla f = 0$, else use Lagrange multiplier method.</p>
]]></content:encoded><category>math</category></item><item><title>Hessian matrix</title><link>https://alchemmist.xyz/articles/hessian-matrix/</link><pubDate>Sat, 05 Jul 2025 12:48:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/hessian-matrix/</guid><description>Imagine we got function and a few stationary points of this function, and we need to classify them, like: max, min or saddle point. If function without constraints, we can use Hessian matrix.
How to find stationary points of the function you can read at this article: “Stationary points and Lagrange method”
Let’s learn it on example. Function and stationary points: $$ f(x, y) = x^3 + y^3 - 3xy; \quad A = (0; 0), \ B = (1; 1) $$ Firstly, build Hessian matrix. In general form Hessian matrix looks like:</description><content:encoded><![CDATA[<p>Imagine we got function and a few stationary points of this function, and we need to classify them, like: max, min or saddle point. If function without constraints, we can use Hessian matrix.</p>
<blockquote class="markdown-blockquote">
  <p>How to find stationary points of the function you can read at this article: “<a href="/articles/stationary-points-and-lagrange/">Stationary points and Lagrange method</a>”</p>

</blockquote>
<p>Let’s learn it on example. Function and stationary points:
</p>
$$
f(x, y) = x^3 + y^3 - 3xy; \quad A = (0; 0), \ B = (1; 1)
$$<p>
Firstly, build Hessian matrix. In general form Hessian matrix looks like:
</p>
$$
H_f(x) =
\begin{bmatrix}
\displaystyle \frac{\partial^2 f}{\partial x_1^2} & \displaystyle \frac{\partial^2 f}{\partial x_1 \partial x_2} & \cdots & \displaystyle \frac{\partial^2 f}{\partial x_1 \partial x_n} \\
\displaystyle \frac{\partial^2 f}{\partial x_2 \partial x_1} & \displaystyle \frac{\partial^2 f}{\partial x_2^2} & \cdots & \displaystyle \frac{\partial^2 f}{\partial x_2 \partial x_n} \\
\vdots & \vdots & \ddots & \vdots \\
\displaystyle \frac{\partial^2 f}{\partial x_n \partial x_1} & \displaystyle \frac{\partial^2 f}{\partial x_n \partial x_2} & \cdots & \displaystyle \frac{\partial^2 f}{\partial x_n^2}
\end{bmatrix}
$$<p>
For our function it is: $H = \begin{bmatrix}6x & -3 \\-3 & 6y\end{bmatrix}$. Then substitute points in this matrix and find eigenvalues:
</p>
$$
\begin{align}
&H_A = \begin{bmatrix}0 & -3 \\ -3 & 0\end{bmatrix} 
&&H_B = \begin{bmatrix}6 & -3 \\ -3 & 6\end{bmatrix} 
\\[1em]
&\det(H_A - \lambda I) = 
\det \begin{bmatrix}
0 - \lambda & -3 \\
-3 & 0 - \lambda
\end{bmatrix} =
&&\det(H_B - \lambda I) = \det \begin{bmatrix}
6 - \lambda & -3 \\
-3 & 6 - \lambda
\end{bmatrix} =
\\
&= (-\lambda)(-\lambda) - (-3)(-3) = \lambda^2 - 9 = 0 \ \Rightarrow \quad \quad \quad \quad
&&= (6-\lambda)^2 - 9 = 0 \ \Rightarrow
\\[1em]
&\Rightarrow \ \lambda^2 = 9 \ \Rightarrow \  \lambda = \pm 3 \ \Rightarrow
&&\Rightarrow \ (6-\lambda)^2 = 9 \ \Rightarrow \ 6 - \lambda = \pm 3 \ \Rightarrow
\\[1em]
&\Rightarrow \lambda_1 = 3, \quad \lambda_2 = -3
&&\Rightarrow \lambda_1 = 6 - 3 = 3, \quad \lambda_2 = 6 + 3 = 9
\end{align}
$$<p>
Then use this rules:</p>
<ul>
<li>If Hessian eigenvalues is positives, point is local minimum</li>
<li>If Hessian eigenvalues is negative, point is local maximum</li>
<li>If Hessian eigenvalues not defined, point is saddle</li>
</ul>
<p>As result, point $A$ it is saddle point and point $B$ it is local minimum.</p>
]]></content:encoded><category>math</category></item><item><title>Subsapces</title><link>https://alchemmist.xyz/articles/subspaces/</link><pubDate>Thu, 03 Jul 2025 10:42:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/subspaces/</guid><description>Start with useful definition: Non-zero vectors $u, v \in \mathbb{R}$ call collinear vectors, if they are proportional to each other, that is exist $\lambda \in \mathbb{R}$, that $u = \lambda v$. Collinear vectors denoted as $u || v$. Zero-vector collinear with any vector. Geometrically, vectors collinear, if they have same or opposite direction.
Let’s consider the plane $\pi$ in $\mathbb{R}^3$ space, which passes through zero-coordinate. Consider two non-collinear vectors $u$ an $v$ from this plane. Then, any point $x \in \pi$ we can be represented as: $x = \alpha u + \beta v$.</description><content:encoded><![CDATA[<p>Start with useful definition: Non-zero vectors $u, v \in \mathbb{R}$ call <strong>collinear vectors</strong>, if they are proportional to each other, that is exist $\lambda \in \mathbb{R}$, that $u = \lambda v$. Collinear vectors denoted as $u || v$. Zero-vector collinear with any vector. Geometrically, vectors collinear, if they have same or opposite direction.</p>
<p>Let’s consider the plane $\pi$ in $\mathbb{R}^3$ space, which passes through zero-coordinate. Consider two non-collinear vectors $u$ an $v$ from this plane. Then, any point $x \in \pi$ we can be represented as: $x = \alpha u + \beta v$.</p>
<p><img
    src="/images/two-vectors-on-plane_hu_f81c1a3af72a6417.webp"
    width="1600"
    height="883"
    class="content-img" style="width:400px"
    alt=""
    loading="lazy"
    decoding="async"
  />
Okay, it’s mean we can define plane $\pi$  as:
</p>
$$
\pi = \{\text{all vectors }\  x \ \text { represented as }\ x = \alpha u + \beta v\}
$$<p>
Let’s generalize the concept of a plane passing through the origin to a space of arbitrary dimension:
The linear <strong>Span</strong> of vectors $v_1, v_2, \dots, v_k \ \in \ \mathbb{R}^n$ is called set of vectors, represented in form of sum of vectors $v_1, v_2, \dots, v_k$ with arbitrary ratio:
</p>
$$
P = \text{span}{(v_1, v_2, \dots, v_k)} = \{ x: \ x = \alpha_1 v_1 + \alpha_2 v_2 + \dots + \alpha_k v_k, \ \alpha_i \in \mathbb{R} \}.
$$<p>
Expression $\alpha_1 v_1 + \alpha_2 v_2 + \dots + \alpha_k v_k$ will call linear combination of vectors $v_1, v_2, \dots, v_k$.</p>
<p>Let’s final this with pivotal definition: <strong>linear subspace</strong> $\mathbb{R}^n$ called span of finite numbers of vectors $v_1, v_2, \dots v_k \ \in \mathbb{R}^n$:
</p>
$$
V = \text{span}(v_1, v_2, \dots, v_k)
$$<p>
The span concept and subspace concept equivalents. And any span and subspace contain a $0$, because we can make all ratio $\alpha_1, \alpha_2, \dots, \alpha_k$ equal to zero .</p>
<p>Why linear subspace is important? Here is an example:</p>
<blockquote class="markdown-blockquote">
  <p>Let us take a black-and-white digital photograph of size 512 by 512 pixels. In computer memory, this photograph can be represented as $512 \times 512 = 262144$ numbers — each representing the intensity of the corresponding pixel, ranging from 0 (completely black) to 1 (completely white). Thus, the photograph can be represented as a vector $x$ in a space of dimension $d=262144$.</p>
<p>Now, let us consider an important practical problem — compressing the photograph without significant loss. It turns out that this problem can be solved by finding a special low-dimensional subspace and projecting the vector $x$ onto this subspace.</p>

</blockquote>
<p>We told, that subspace need to contain zero. It’s mean line $y = 2x$ is a subspace, but line $y = x + 2$ not. But many properties of subspace saved when it doesn’t contain zero. Therefore, we call such subspaces as affine subspaces. <strong>Affine subspaces</strong> of $\mathbb{R}^n$ is a set of vectors $A$ of the form $a + v$, where $a \in \mathbb{R}^n$ — is a fixed vector, and vector $v$ belongs to linear subspace $V$. Let linear subspace $V$ is span of vectors $v_1, v_2, \dots, v_k$. Then, affine affine subspace is a set:
</p>
$$
A = \{ x: \ x = a + \alpha_1 v_1 + \alpha_2 v_2 + \dots + \alpha_k v_k, \ \alpha_i \in \mathbb{R}\}
$$<p>
Let $V$ — subspace in $\mathbb{R}^n$. <strong>Dimension</strong> of this subspace is minimal count of vectors $v_1, v_2, \dots, v_k \in \mathbb{R}^n$ for define subspace $V$:
</p>
$$
V = \text{span}(v_1, v_2, \dots, v_k).
$$<p>
Dimension is denoted by: $\dim{(V)}$.
Let’s think about it. For example, we have two non-collinear vectors $u, v \in \mathbb{R}^{100}$ and subspace $V = \text{span}(u, v)$. We know every vector $x \in V$ have 100 coordinates, but, by subspace definition: $x = \alpha u + \beta v$. it’s mean any vector $x$ defined only two parameters $\alpha$ and $\beta$, therefore $\dim{(V))} = 2$. For define point in $\mathbb{R}^n$ we need $n$ parameters, for define point in $V$ we need $\dim{(V)}$ parameters.</p>
<p><img
    src="/images/define-subspace_hu_d2ba0211e5bef597.webp"
    width="1600"
    height="497"
    class="content-img" style="width:800px"
    alt=""
    loading="lazy"
    decoding="async"
  /></p>
<p>Exist subspace, which defined only one vector $0$: $V = \text{span}(0)$. We call this subspace trivial, and considered $\dim{(V)} = 0$.</p>
<p>If we have subspace $V = \text{span}(v_1, v_2, \dots, v_k)$, when $\dim{(V)}$ can be smaller than $k$? if and only if one of the vectors can be express as linear combination rest vectors, for example: $v_1 = \gamma_2v_2 + \gamma_3v_3 + \dots + \gamma_kv_k$.</p>
<p>Set of vectors called <strong>linearly independent</strong> if equality:
</p>
$$
\alpha_1 v_1 + \alpha_2 v_2 + \dots + \alpha_k v_k = 0
$$<p>
holds only for $\alpha_1 = \alpha_2 = \dots = \alpha_k = 0$. If equality can be holds for non-zero rates, vectors <strong>linearly dependent</strong>.</p>
<p>Consider space $\mathbb{R}^n$ and a given non-zero vector $w \in \mathbb{R}^n$ . Then set of vectors $P$, perpendicular $w$:
</p>
$$
P = \{ \ x: \langle x;w \rangle = 0\ \}
$$<p>
is linear subspace with $\dim{(P)} = n - 1$</p>
]]></content:encoded><category>math</category></item><item><title>Line and plane</title><link>https://alchemmist.xyz/articles/line-and-plane/</link><pubDate>Sat, 28 Jun 2025 17:18:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/line-and-plane/</guid><description>The Linear Algebra starts from basic geometry intuition, which continues to multivariate spaces. Now we will talk about line, plane and space.
# The line in plane and space How to define a line in plane? Of course, through two points. But it’s not all. Exists are three more methods:
Parametric equation Let line $l$ set by two points $r_0 = (x_0; y_0)$ and $r_1 = (x_1;y_1)$. Observe that vector $a = r_0 - r_1$ in same direction with $l$. Therefore, any point on $l$ may define as $r = r_0 + ta$, where $t \in \mathbb{R}$ and full line $l$ way be with $-\infty &amp;lt; t &amp;lt; \infty$. This expression we call parametric equation:</description><content:encoded><![CDATA[<p>The Linear Algebra starts from basic geometry intuition, which continues to multivariate spaces. Now we will talk about line, plane and space.</p>

<h2 id="the-line-in-plane-and-space">
  <a class="link" href="#the-line-in-plane-and-space">
    #
  </a>
  The line in plane and space
</h2>

<p>How to define a line in plane? Of course, through two points. But it’s not all. Exists are three more methods:</p>
<ol>
<li>
<p><strong>Parametric equation</strong>
Let line $l$ set by two points $r_0 = (x_0; y_0)$ and $r_1 = (x_1;y_1)$. Observe that vector $a = r_0 - r_1$ in same direction with $l$. Therefore, any point on $l$ may define as $r = r_0 + ta$, where $t \in \mathbb{R}$ and full line $l$ way be with $-\infty < t < \infty$. This expression we call <em>parametric equation</em>:
</p>
$$
l = \{r: r = r_o + at, \ t \in \mathbb{R} \}
$$</li>
<li>
<p><strong>Linear equation</strong>
Let’s write the parametric equation using coordinates:
</p>
$$
\begin{bmatrix}x \\ y\end{bmatrix} = \begin{bmatrix}x_0\\y_0\end{bmatrix} + \begin{bmatrix}t \cdot a_1 \\ t \cdot a_2\end{bmatrix} \Rightarrow \begin{cases}x = x_0 + ta_1 \\ y = y_0 + ta_2\end{cases}
$$<p>
Suppose that, $a_1 \neq 0$ and $a_2 \neq 0$ and solve $t$ from each equation: $\frac{x - x_0}{a_1} = \frac{y - y_0}{a_2} \Rightarrow a_2x - a_1y + (a_1y_0 - a_2x_0) = 0$. Since $a_1, a_2, x_0, x_1$ it’s a numbers, that mean we can define it as linear equation:
</p>
$$
Ax + By + C = 0
$$<p>
where $A = a_2$, $B = -a_1$, $C = (a_1y_0 - a_2x_0)$</p>
</li>
<li>
<p><strong>Normal and translation</strong>
Last method. Let’s select random point on line $l$ with radius-vector $r_0$. Let’s draw a vector $n$ from point $r_0$, that is perpendicular line $l$. Then for any point $r$ on line $l$ vectors $r - r_0$ and $n$ will be perpendicular. Rewrite it with scalar product:
</p>
$$
l = \{ r: \langle r - r_0;n\rangle = 0\}
$$<p>
Of course, $r_0$ it can by any point on line $l$ and normal vector $n$ any vector perpendicular to line $l$. To find normal to line, we need direction vector $a = \begin{pmatrix}a_1 \\ a_2\end{pmatrix}$ from <em>parametric equation</em> and then normal vector will be: $n = \begin{bmatrix}-a_2\\ a_1\end{bmatrix}$ or $n’ = -n = \begin{bmatrix} a_2 \\ -a_1\end{bmatrix}$</p>
</li>
</ol>
<p>Let’s resume and see the relationship between this methods. If line passes through two points $r_0 = (x_0; y_0)$ and $r_1 = (x_1; y_1)$, then his can be define of of the three methods:</p>
<ul>
<li>parametric equation :

$$
r = r_0 + ta = \begin{bmatrix}x_0\\y_0\end{bmatrix} + t \cdot \begin{bmatrix}x_1 - x_0 \\ y_1 - y_0\end{bmatrix} = \begin{bmatrix}x_0\\y_0\end{bmatrix} + \begin{bmatrix}t \cdot a_1 \\ t \cdot a_2\end{bmatrix}
$$</li>
<li>linear equation:

$$
Ax + By + C = 
\underbrace{a_2}_{A} x + 
\underbrace{(-a_1)}_{B} y + 
\underbrace{(a_1 y_0 - a_2 x_0)}_{C} = 0;
$$</li>
<li>normal and translation:

$$
\langle r - r_0; n\rangle = \left\langle \begin{bmatrix}x - x_0\\y - y_0\end{bmatrix}; \begin{bmatrix}a_1 \\ -a_1\end{bmatrix}\right\rangle = \left\langle\begin{bmatrix}x - x_0 \\ y - y_0\end{bmatrix}; \begin{bmatrix}A \\ B\end{bmatrix} \right\rangle
$$
What about line in space? Parametric equation doesn’t change, one vectors will get longer. Linear equation will change: now it’s not one equation, it’s system of two equations:

$$
\begin{cases}
a_2x - a_1y + (a_1y_0 - a_2x_0) = 0 \\
a_3y - a_2z + (a_2z_0 - a_3y_0) = 0
\end{cases}
$$
Method with normal and translation <strong>not working in space</strong>!</li>
</ul>
<p>Addition: let’s take to look at <strong>distance from point to line:</strong>
</p>
$$
d(P, l) = \frac{|Ax_0 + By_0 + C|}{\sqrt{A^2 + B^2}}
$$<p>
And we can detect where point relative to a line: group of points from one side, for which $Ax +By + C > 0$ is true; group from another side, for which $Ax +By + C < 0$ is true.</p>

<h2 id="the-plane-in-space">
  <a class="link" href="#the-plane-in-space">
    #
  </a>
  The plane in space
</h2>

<p>Again this question. How to define a plane in space? Of course, through with three points non-collinear, that do not lie on the same straight line. <strong>Collinear points</strong> lie on the same line. And again let’s consider three methods:</p>
<ol>
<li><strong>Parametric equation</strong>:

$$
\pi = \{r: r = r_0 + t_1v_1 + t_2v_2, \quad t_1, t_2 \in \mathbb{R}\}
$$</li>
<li><strong>Normal and translation</strong> is the same as for line: $\langle r - r_0; n\rangle = 0$</li>
<li><strong>Linear equation:</strong> start from normal and translation and expand it:

$$
\langle r - r_0; n\rangle = 0 \quad \Rightarrow \quad 
\underbrace{n_1}_{A} x\  + \ 
\underbrace{n_2}_{B} y\  + \
\underbrace{n_3}_{C} z \ 
\underbrace{- \langle r_0 ;n\rangle}_{D} = 0. \ \Rightarrow \ Ax + By + Cz + D = 0
$$
Let’s look to relationship between this methods:</li>
</ol>
<ul>
<li>For rewrite parametric equation to normal and translation we need to find normal vector from this system of equations: $\begin{cases}\langle n; v_1\rangle = 0 \\ \langle n; v_2\rangle = 0\end{cases}$</li>
<li>For rewrite normal and translation form to linear equation we can use this: $A = n_1$, $B = n_2$, $C = n_3$, $D = -\langle n ;r_0\rangle$</li>
<li>If we have three points, defined plane, we can go to parametric equation: $\begin{array}a v_1 = r_1 - r_0\\ v_2 = r_2 - r_0\end{array}$</li>
</ul>
<p>Projection point $P$ on plan $\pi$ we call point $P_\pi \in \pi$, the closest to the point $P$: $P_\pi = \arg{\min{||P - X||}}, \ X \in \pi$. Then, the distance from point $P$ to plane $\pi$ will be $d(P, \pi)$ — the distance between point $P$ and her projection $P_\pi$:
</p>
$$
d(P, \pi) = \frac{|Ax_0 + By_0 + Cz_0 + D|}{\sqrt{A^2 + B^2 + C^2}}
$$<p>
Detecting where point relative a plane is the same as line.</p>
]]></content:encoded><category>math</category></item><item><title>Base of multivariate vectors</title><link>https://alchemmist.xyz/articles/multivariate-vectors/</link><pubDate>Thu, 26 Jun 2025 14:18:00 +0300</pubDate><dc:creator>alchemmist</dc:creator><guid>https://alchemmist.xyz/articles/multivariate-vectors/</guid><description>What is a vector? For natural number $n$ will call a n-variate vector list of n ordered real numbers $v = \begin{pmatrix}v_1&amp;amp;v_2&amp;amp;v_3&amp;amp;\ldots&amp;amp;v_n\end{pmatrix}$. Well the $n$ number is a vector dimension: $\dim{v} = n$. For $n$ number the set of all possible vectors will call $R^n$. The regular number we call “scalar”. For example, $5 \ - \ scalar$, but $\begin{pmatrix}1&amp;amp;3\end{pmatrix} \ - \ vector$.
# The basic operations of vectors Sum of vectors is a sum of corresponding coordinates: $$ v + w = \begin{pmatrix}v_1 \\ v_2 \\ \ldots \\ v_n \end{pmatrix} + \begin{pmatrix}w_1 \\ w_2 \\ \ldots \\ w_n \end{pmatrix} = \begin{pmatrix}v_1 + w_1 \\ v_2 + w_2 \\ \ldots \\ v_n + w_n \end{pmatrix} $$ We can add vectors only they have same dimension. 2. Product of vector by scalar is a product off each coordinates by a scalar:</description><content:encoded><![CDATA[<p>What is a vector? For natural number $n$ will call a n-variate <strong>vector</strong> list of n ordered real numbers $v = \begin{pmatrix}v_1&v_2&v_3&\ldots&v_n\end{pmatrix}$. Well the $n$ number is a vector dimension: $\dim{v} = n$. For $n$ number the set of all possible vectors will call $R^n$.
The regular number we call “scalar”. For example, $5 \ - \ scalar$, but $\begin{pmatrix}1&3\end{pmatrix} \ - \ vector$.</p>

<h2 id="the-basic-operations-of-vectors">
  <a class="link" href="#the-basic-operations-of-vectors">
    #
  </a>
  The basic operations of vectors
</h2>

<ol>
<li>Sum of vectors is a sum of corresponding coordinates:

$$
v + w = \begin{pmatrix}v_1 \\ v_2 \\ \ldots \\ v_n \end{pmatrix} + \begin{pmatrix}w_1 \\ w_2 \\ \ldots \\ w_n \end{pmatrix} = \begin{pmatrix}v_1 + w_1 \\ v_2 + w_2 \\ \ldots \\ v_n + w_n \end{pmatrix}
$$</li>
</ol>
<p>We can add vectors only they have same dimension.
2. Product of vector by scalar is a product off each coordinates by a scalar:
</p>
$$
\lambda v = \lambda \cdot \begin{pmatrix}v_1 \\ v_2 \\ \ldots \\ v_n \end{pmatrix} = \begin{pmatrix}\lambda v_1 \\ \lambda v_2 \\ \ldots \\ \lambda v_n \end{pmatrix}
$$<p>
3. Difference of vectors is a sum of vectors, but one of vector product by scalar $-1$.
4. Scalar product of vectors:
</p>
$$
x \cdot y = \langle x;y\rangle = x_1 y_1 + x_2 y_2 + \ldots + x_n y_n = \sum \limits_{i = 1}^{n}x_i y_i
$$<p>
Properties of scalar vectors product:</p>
<ul>
<li>Commutativity: $\langle v; w\rangle = \langle w; v\rangle$</li>
<li>Distributivity over addition: $\langle x; (v + w)\rangle = \langle x; v\rangle + \langle x; w \rangle$</li>
<li>Compatibility with scalar multiplication: $\langle v; \lambda w\rangle = \lambda \langle v;w\rangle$</li>
<li>If scalar product equal zero we call this two vectors <em>orthogonal</em> or <em>perpendicular</em></li>
</ul>

<h2 id="geometric-meaning">
  <a class="link" href="#geometric-meaning">
    #
  </a>
  Geometric meaning
</h2>

<p>In geometry vector is a segment having a direction.
<img
    src="/images/the-vector_hu_3dba13051fbe9e9b.webp"
    width="984"
    height="628"
    class="content-img" style="width:400px"
    alt=""
    loading="lazy"
    decoding="async"
  /></p>
<p>The <strong>length</strong> of vector we calculate with Pythagoras’s theorem: $||v|| = \sqrt{\sum\limits_{i = 1}^{n}{x_i}}$. If length of vector equal one we call it a <strong>unit vector</strong>. If $v$ not a unit vector we can change it multiplying by $\lambda = \frac{1}{||v||}$. We can calculate distance and angle between two vectors.  <strong>Distance</strong> is a length of difference two vectors: $d = ||v - w|| = \sqrt{\sum\limits_{i = 1}^{n}{(v_i - w_i)^2}}$. <strong>Angle</strong> between two vectors follows from Law of Cosines:
</p>
$$
\cos{\theta} = \frac{\langle u;b \rangle}{||u||\ ||v||}
$$<p>
Often be helpful: $||u|| = \sqrt{\langle u;u\rangle}$. Next operation is <strong>projection vector $u$ to vector $w$</strong>:
</p>
$$
Proj_w(u) = \frac{\langle u;w\rangle}{||w||^2}w
$$<p>
Another property of vectors: module of scalar product does not exceed product of their length — the <strong>Cauchy–Schwarz inequality</strong>:
</p>
$$
-||v||\ ||w|| \leqslant \langle v;w\rangle \leqslant ||v||\ ||w||
$$<p>
The <strong>Triangle inequality:</strong> $||v + w|| \leqslant ||v|| + ||w||$, so length of sum of vectors less than or equal to sum of vectors lengths. If vectors is orthogonal, work the Pythagoras’s theorem: $||a + b||^2 = ||a||^2 + ||b||^2$.</p>
]]></content:encoded><category>math</category></item></channel></rss>