ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jeong Dal via ntg-context <ntg-context@ntg.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Cc: Jeong Dal <haksan@mac.com>
Subject: [NTG-context] Re: wiki update: Modules
Date: Mon, 2 Oct 2023 10:14:03 +0900	[thread overview]
Message-ID: <3762160F-54D6-41B1-9101-64B71173E89C@mac.com> (raw)
In-Reply-To: <e48b9047-d847-7dac-d7e3-c637ee68b6ae@fiee.net>

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

Dear Hraban,

When I wrote a class material for Linear Algebra, it is nice to use \pmatrix and \bmatrix etc. 
But, for example, to write a result matrix of the product of two matrices, I need to calculate it somewhere and copy it to my text. Hence, I tried to use Lua to handle it in the ConTeXt. And, it is nicely working.
During the process, I asked many questions to Hans and he gladly helped me.
It is the first time for me to code using Lua, so my coding was clumsy. However,  Hans corrected it to be usable in ConTeXt even though he is very very busy in many things.
And, he made it a module and put it in the list.
Thanks Hans.

Finally I finished several chapters on Linear Algebra using that code.
It was many years ago.
Here is a document of it. I confirm that it is running well without any problem.

I hope that someone who wants to write an article on Linear Algebra use it.

Thanks for reading.

Best regards,

Dalyoung



[-- Attachment #2: matrixDoc.tex --]
[-- Type: application/octet-stream, Size: 8720 bytes --]

\usemodule[m-matrix]
\usemodule[art-01]

\starttext

\startluacode
document.DemoMatrixA = {
    { 0, 2,  4, -4, 1 },
    { 0, 0,  2,  3, 4 },
    { 2, 2, -6,  2, 4 },
    { 2, 0, -6,  9, 7 },
    { 2, 3,  4,  5, 6 },
    { 6, 6, -6,  6, 6 },
}

document.DemoMatrixB = {
    { 0, 2,  4, -4, 1 },
    { 0, 0,  2,  3, 4 },
    { 2, 2, -6,  3, 4 },
    { 2, 0, -6,  9, 7 },
    { 2, 2, -6,  2, 4 },
}

document.DemoMatrixC = {
    {  3, 3, -1,  3 },
    { -1, 4,  1,  3 },
    {  5, 4,  0,  2 },
    {  2, 4,  0, -1 },
}
\stopluacode

\startbuffer[demo]
\typebuffer
\startalignment[middle]
    \dontleavehmode\inlinebuffer
\stopalignment
\stopbuffer

\setuphead[section][before={\testpage[5]\blank[2*big]}]

\startsubject[title={A symbolic matrix}]

\startbuffer
\ctxmodulematrix{typeset(moduledata.matrix.symbolic("a", "m", "n"))}
$\qquad\qquad$
\ctxmodulematrix{typeset(moduledata.matrix.symbolic("a", "m", "n", 4, 8))}
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={Generate a new $m \times n$ matrix}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(moduledata.matrix.makeR(4,3, 0,5))
    context.qquad()
    context("\\qquad")
    moduledata.matrix.typeset(moduledata.matrix.makeR(5,5,-1,5))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={Swap two rows (ex: 2 and 4)}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.typeset(moduledata.matrix.swaprows(document.DemoMatrixA,2,4))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={Swap two columns (ex: 1 and 3)}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.typeset(moduledata.matrix.swapcolumns(document.DemoMatrixA,1, 3))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={Multiply 3 to row 2($3 \times r_2$)}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.typeset(moduledata.matrix.multiply(document.DemoMatrixA,2,3))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={Add 4 times of row 3 to row 2($r_2 + 4 \times r_3$)}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.sumrow(document.DemoMatrixA,2,3,4)
    moduledata.matrix.typeset(document.DemoMatrixA)
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={Transpose a matrix}]
\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.typeset(moduledata.matrix.transpose(document.DemoMatrixA))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={The inner product of two vectors}]

\startbuffer
\startluacode
    context("$<1,2,3> \\cdot <3,1,2> \\ =\\ $ ")
    context( moduledata.matrix.inner({ 1, 2, 3 }, { 3, 1, 2 }))
\stopluacode
\stopbuffer

\getbuffer[demo]

\startbuffer
\startluacode
context("$<1,2,3> \\cdot <3,1,2,4> \\ =\\ $ ")
context(moduledata.matrix.inner({ 1, 2, 3 }, { 1, 2, 3, 4 }))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={The product of two matrices}]

\startbuffer
\startluacode
    context("$\\ $")
    moduledata.matrix.typeset(document.DemoMatrixB)
    context("$\\cdot$")
    moduledata.matrix.typeset(document.DemoMatrixA)
    context("$ = $")
    moduledata.matrix.typeset(moduledata.matrix.product
        (document.DemoMatrixB,document.DemoMatrixB))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={An Upper Triangular Matrix}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixB)
    context("$\\qquad \\Rightarrow \\qquad$")
    moduledata.matrix.typeset(moduledata.matrix.uppertri(document.DemoMatrixB))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={Determinant: using triangulation}]

\startbuffer
\startluacode
    local m = {
        { 1, 2,  4 },
        { 0, 0,  2 },
        { 2, 2, -6 },
        { 2, 2, -6 },
    }
    moduledata.matrix.typeset(m, {fences="bars"})
    context("$\\qquad = \\qquad$")
    context(moduledata.matrix.determinant(m))
\stopluacode
\stopbuffer
\getbuffer[demo]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixC, { fences = "bars" })
    context("$\\qquad = \\qquad$")
    context(moduledata.matrix.determinant(document.DemoMatrixC))
\stopluacode
\stopbuffer
\getbuffer[demo]

\stopsubject

\startsubject[title={Determinant: using Laplace Expansion}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(document.DemoMatrixC, { fences = "bars" })
    context("$\\qquad = \\qquad$")
    context(moduledata.matrix.laplace(document.DemoMatrixC))
\stopluacode
\stopbuffer
\getbuffer[demo]

\stopsubject

\startsubject[title={Example of Laplace Expansion using submatrix function}]

\startbuffer
\startluacode
    local m = {
        { 1, 5, 4, 2 },
        { 5, 2, 0, 4 },
        { 2, 2, 1, 1 },
        { 1, 0, 0, 5 },
    }
    local options = {fences = "bars"}

    moduledata.matrix.typeset(m,options)
    context("\\par $=$")
    for j = 1, #m[1] do
        local mm =  moduledata.matrix.submatrix(m, 1, j)
        local factor = (-1)^(1+j) *(m[1][j])
        context("\\ ($%d$) \\cdot ", factor)
        moduledata.matrix.typeset(mm, options)
        if j < #m[1] then
            context("\\ $+$ ")
        end
    end
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={Row echelon form}]

\startbuffer
\startluacode
    local m = {
        { 1, 3, -2,  0, 2,  0,  0 },
        { 2, 6, -5, -2, 4, -3, -1 },
        { 0, 0,  5, 10, 0, 15,  5 },
        { 2, 6,  0,  8, 4, 18,  6 },
    }
    moduledata.matrix.typeset(m)
    context("$\\Rightarrow$")
    moduledata.matrix.typeset(moduledata.matrix.rowechelon(m,1))
\stopluacode

\stopbuffer

\getbuffer[demo]

\stopsubject


\startsubject[title={Solving linear equation}]

\startbuffer
\startluacode
    local m = {
        {  1,  3, -2,  0 },
        {  2,  0,  1,  2 },
        {  6, -5, -2,  4 },
        { -3, -1,  5, 10 },
    }

    local c = { 5, 2, 6, 8 }

    moduledata.matrix.typeset(moduledata.matrix.solve(m,c))
    context.blank()
    moduledata.matrix.typeset(moduledata.matrix.solve(m,c), { template = 6 })
    context.blank()
    moduledata.matrix.typeset(moduledata.matrix.solve(m,c), { template = "no" })
    context.blank()
    moduledata.matrix.typeset(moduledata.matrix.solve(m,c), { template = "%0.3f" })
    context.blank()
    moduledata.matrix.typeset(moduledata.matrix.solve(m,c), { template = "%0.4F" })
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={Inverse matrix}]

\startbuffer
\startluacode
    local m = {
        { 1, 1, 1 },
        { 0, 2, 3 },
        { 3, 2, 1 },
    }
    context("$A =\\quad$")
    moduledata.matrix.typeset(m)
    context("$\\qquad A^{-1} = \\quad$")
    moduledata.matrix.typeset(moduledata.matrix.inverse(m))
    context("\\blank\\ ")
    moduledata.matrix.typeset(m)
    context("$\\cdot$")
    moduledata.matrix.typeset(moduledata.matrix.inverse(m))
    context("$ = $")
    moduledata.matrix.typeset(moduledata.matrix.product(m, moduledata.matrix.inverse(m)))
\stopluacode
\stopbuffer

\getbuffer[demo]

\stopsubject

\startsubject[title={make matrices(zero, identiry, random)}]

\startbuffer
\startluacode
    moduledata.matrix.typeset(moduledata.matrix.makeM(3, 0))
    context.qquad()
    moduledata.matrix.typeset(moduledata.matrix.makeM(3, 1))
    context.qquad()
    moduledata.matrix.typeset(moduledata.matrix.makeR(4,3))
\stopluacode
\stopbuffer
\getbuffer[demo]

\stopsubject

\startsubject[title={join rows, join columns}]

\startbuffer
\startluacode
    local mat1, mat2
    	mat1 = moduledata.matrix.makeR(3, 4)
	mat2 = moduledata.matrix.makeR(4, 3)
    
    context("Appending as columns: ")
    context.blank()
    moduledata.matrix.typeset(mat1)
    context("$\\&$")
    moduledata.matrix.typeset(mat1)
    context("\\quad $\\Rightarrow$ \\quad")
    moduledata.matrix.joinColumns(mat1, mat1)
    moduledata.matrix.typeset(mat1)
    context.blank()
    context("Appending as rows: ")
    context.blank()
    moduledata.matrix.typeset(mat2)
    context("$\\&$")
    moduledata.matrix.typeset(mat2)
    context("\\quad $\\Rightarrow$ \\quad")
    moduledata.matrix.joinRows(mat2, mat2)
    moduledata.matrix.typeset(mat2)    
\stopluacode
\stopbuffer
\getbuffer[demo]

\stopsubject

\stoptext

[-- Attachment #3: Type: text/plain, Size: 1313 bytes --]




> 2023. 10. 1. 오후 6:01, Henning Hraban Ramm <texml@fiee.net> 작성:
> 
> Am 01.10.23 um 05:51 schrieb Otared Kavian:
>> Hi Hraban,
>> Thank you for your updating of the modules stuff.
>> As far as I remember the matrix features are not related to any modules, but rather are part of LMTX. In nay case next week I will look at the page
>> https://wiki.contextgarden.net/Matrix_in_maths <https://wiki.contextgarden.net/Matrix_in_maths>
>> and verify that eveything on that page works fine and is up to date.
> 
> Thank you!
> 
> But there _is_ a matrix module (hey, I just looked through all this stuff!) by Jeong Dalyoung & Hans; apparently it can do matrix calculations.
> 
> https://source.contextgarden.net/tex/context/modules/mkiv/m-matrix.mkiv
> 
> Hraban
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : https://contextgarden.net
> ___________________________________________________________________________________


[-- Attachment #4: Type: text/plain, Size: 495 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2023-10-02  1:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30 11:53 [NTG-context] " Henning Hraban Ramm
2023-10-01  3:51 ` [NTG-context] " Otared Kavian
2023-10-01  9:01   ` Henning Hraban Ramm
2023-10-02  1:14     ` Jeong Dal via ntg-context [this message]
2023-10-02 19:45     ` Hans Hagen
2023-10-02  2:00 Andres Conrado Montoya
2023-10-02  8:19 ` Henning Hraban Ramm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3762160F-54D6-41B1-9101-64B71173E89C@mac.com \
    --to=ntg-context@ntg.nl \
    --cc=haksan@mac.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).