<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nattawat Piansakul on Medium]]></title>
        <description><![CDATA[Stories by Nattawat Piansakul on Medium]]></description>
        <link>https://medium.com/@boatchaos179?source=rss-5d9d9bb4ad49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E8Vg8G9cfKrwUggKVGmO5w.jpeg</url>
            <title>Stories by Nattawat Piansakul on Medium</title>
            <link>https://medium.com/@boatchaos179?source=rss-5d9d9bb4ad49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:14:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boatchaos179/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[เครื่องจักรสถานะการทำงาน(state machine) ด้วยหลักการผลรวมเชิงเส้น(Linear combination)]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87%E0%B8%88%E0%B8%B1%E0%B8%81%E0%B8%A3%E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%99%E0%B8%B0%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%97%E0%B8%B3%E0%B8%87%E0%B8%B2%E0%B8%99-state-machine-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%AB%E0%B8%A5%E0%B8%B1%E0%B8%81%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%9C%E0%B8%A5%E0%B8%A3%E0%B8%A7%E0%B8%A1%E0%B9%80%E0%B8%8A%E0%B8%B4%E0%B8%87%E0%B9%80%E0%B8%AA%E0%B9%89%E0%B8%99-linear-combination-8a58ec50e5cc?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a58ec50e5cc</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 31 Oct 2018 08:32:15 GMT</pubDate>
            <atom:updated>2018-10-31T08:32:15.973Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/185/1*qkttuABnH4pyLSVcuag9BA.png" /></figure><p>จากภาพยนต์เรื่อง <strong>Die Hard 3 </strong>John McClain (Bruce Willis) and Zeus (Samuel L. Jackson) ได้รับข้อเสนอจาก Peter Krieg (Jeremy Irons)</p><p>โดยมีเหยือกน้ำ 5 แกลลอน และ เหยือกน้ำ 3 แกลลอน ให้เติมน้ำใส่ถัง 5 แกลลอนให้ได้ 4 แกลลอน ไม่งั้นทั้งคู่ก็จะตายภายในเวลาที่กำหนด</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBVtQNK_ZUJg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBVtQNK_ZUJg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBVtQNK_ZUJg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/df9287612fd70493bb863950a608b840/href">https://medium.com/media/df9287612fd70493bb863950a608b840/href</a></iframe><p>สามารถเขียนอธิบายด้วยการทำงานของเครื่องจักรสถานะการทำงาน(state machine) ซึ่งเป็นการอธิบายทีละขั้นตอน(step by step)ซึ่งมีความสำคัญในวิทยาการคอมพิวเตอร์(computer science) เพราะ อุปกรณ์คอมพิวเตอร์มีการประมวลผลเป็นขั้นตอน ซึ่งจากภาพยนต์มีความเกี่ยวข้องกับ ทฤษฏ๊จำนวน(Number theory) ซึ่งขอบเขตของปัญหาในภาพยนตร์อยู่ในขอบเขตของจำนวนเต็ม เขียนแทนด้วยสัญลักษณ์เซต คือ ตัว <strong>Z </strong>(ตัวหนา) ซึ่งมาจาก ภาษาเยอรมัน<strong> </strong>Zahlen [ˈtsaːlən] แปลว่าจำนวน มีสมาชิกในเซต คือ {…,-2,-1,0,1,2,…} ซึ่งมีจำนวนอนันต์(infinity)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/19/1*PXUyNVG9e9H2OoPI7y3fRw.jpeg" /><figcaption>สัญลักษณ์แสดงเซตของจำนวนเต็ม</figcaption></figure><p>ในภาพยนต์ได้ทำการเติมเหยือกน้ำ 3 แกลลอนให้เต็มก่อน แล้วจึงค่อยเติมใส่เหยือกน้ำ 5 แกลลอน เพื่อหาส่วนต่าง</p><p>มีการเรียกปัญหานี้อย่างแพร่หลาย คือ <strong>“ปัญหาเหยือกน้ำ(Water Jug Problem)”</strong></p><p>Mathematics for Computer Science แต่งโดย Eric Lehman, F Thomson Leighton และ Albert R Meyer โดยมหาวิทยาลัย Massachusetts Institute of Technology(MIT) University</p><p>ได้มีแสดงการคำนวณเรื่องปัญหาเหยือกน้ำ(Water Jug Problem)</p><p>a คือ ปริมาตรสูงสุดน้ำในเหยือก(jug)เล็ก</p><p>b คือ ปริมาตรสูงสุดน้ำในเหยือก(jug)ใหญ่</p><p>กรณีที่ b&gt;a และ a,b อยู่ในเซตของจำนวนเต็ม</p><p>และมีเงื่อนไขสำคัญจากผู้เขียนบทความสังเกตุเอง คือ</p><ol><li>การเติมน้ำเข้าเหยือกน้ำว่างเปล่าจะต้องใส่ให้เต็ม(เกิดขึ้นกับเหยือกน้ำเล็กเสมอ)</li></ol><p>2. การเทน้ำออกจากเหยือกน้ำเต็มจะต้องเทออกให้หมด(เกิดขึ้นกับเหยือกน้ำใหญ่เสมอ)</p><p>3.กำหนดให้เหยือกน้ำเล็กอยู่ด้านซ้ายมือ</p><p>4.กำหนดให้เหยือกใหญ่อยู่ด้านขวามือ</p><p>โดยที่ ข้อ 3. และ 4. คือ การกำหนดจุดอ้างอิง(reference)ให้แก่เครื่องจักรสถานะการทำงาน(state machine)</p><p>สามารถเขียนให้อยู่ในรูปแบบทั่วไปได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*yaTR9CfzTFc-u2URhXUp1g.jpeg" /></figure><p>จนได้กระทั่งได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/79/1*5LFaeK3-cD8OPwY4REl44A.jpeg" /></figure><p>อยู่ในผลรวมเชิงเส้น(Linear combination)ของ 2 ตัวแปร(variable)</p><p>โดยที่รูปแบบทั่วไปของผลรวมเชิงเส้น(Linear combination) คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*l-chs2cmWG_MkHtpbikQhg.jpeg" /></figure><p>กล่าว คือ</p><p>สถานะเริ่มต้น(initial state) มีค่า (0,0)</p><p>สถานะสุดท้าย(final state) มีค่า (0,s ×a+t×b)</p><p>โดยที่</p><ol><li>s คือ จำนวนครั้งการเติมน้ำเข้าเหยือกน้ำว่างเปล่า(เกิดขึ้นกับเหยือกน้ำเล็กเสมอ)</li></ol><p>ยกตัวอย่าง (0,0) → (a,0) นับเป็น 1 ครั้ง ใส่ค่า s</p><p>2. t คือ การเทน้ำออกจากเหยือกน้ำเต็ม</p><p>ยกตัวอย่าง (1,5) → (1,0) นับเป็น -1 ครั้ง ใส่ค่า t</p><blockquote>โจทย์จากภาพยนตร์ <strong>Die Hard 3</strong></blockquote><p>มีเหยือกน้ำ 5 แกลลอน และ เหยือกน้ำ 3 แกลลอน ให้เติมน้ำใส่ถัง 5 แกลลอนให้ได้ 4 แกลลอน ไม่งั้นทั้งคู่ก็จะตายภายในเวลาที่กำหนด</p><blockquote>แนวทางการแก้ปัญหา(Solution)ที่แพร่หลาย</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mkvb0f90HIKQUIk0u-dkDg.jpeg" /><figcaption>เหยือกน้ำสองใบด้านซ้ายเป็นเหยือกใหญ่มีปริมาตร 5 แกลลอน ด้านขวาเป็นเหยือกเล็กมีปริมาตร 3 แกลลอน</figcaption></figure><p>วิเคราะห์โจทย์</p><p>หากทำตามภาพยนต์ เหยือกน้ำ 3 แกลลอนให้เต็มก่อน แล้วจึงค่อยเติมใส่เหยือกน้ำ 5 แกลลอน จะเข้ากรณี b&gt;a และ a,b อยู่ในเซตของจำนวนเต็มตามรูปแบบทั่วไป จากตำราเรียน(text book)ของ MIT university</p><p>จากเงื่อนไขเหยือกน้ำเล็กจะวางทางซ้ายเสมอและด้านขวาในภาพจึงวางสลับกัน</p><p>ผู้เขียนบทความขอนำเสนอการแก้ปัญหาในลักษณะที่ิคิดแบบการชนของลูกบิลเลียด(billiard)</p><p>กำหนดพิกัดดังนี้</p><p>(0,0) คือ เหยือกน้ำเล็กมีปริมาตร = 0 และเหยือกน้ำใหญ่ = 0</p><p>กล่าวคือ<strong> “เหยือกน้ำทั้งสองว่างเปล่า”</strong></p><p>(3,5) คือ เหยือกน้ำเล็กมีปริมาตร = 3 และเหยือกน้ำใหญ่ = 5</p><p>กล่าวคือ<strong> “เหยือกน้ำทั้งสองมีน้ำอยู่เต็มปริมาตรที่สามารถใส่ได้แต่ละอัน”</strong></p><p>คือ ระบบพิกัดคาร์ทีเซียน(Cartesian coordinate system) แต่พิจารณาเพียงจตุรภาคที่ 1 (quadrant 1) เพียงเท่านั้น เพราะ ปริมาตรน้ำ(Volume) มีค่ามากกว่าเท่ากับ 0 เสมอ</p><p>กำหนดให้สถานะเริ่มต้น(initial state) มีค่า (0,0)</p><p>สถานะสุดท้าย(final state) มีค่า (0,4) ตามโจทย์ต้องการ เพราะ น้ำปริมาตร 4 ลิตรจะเป็นจริงก็ต่อเมื่อใส่เหยือกน้ำ 5 ลิตรเท่านั้นซึ่งอยู่ด้านขวา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uZ6OBdvt4glu43PZgpp1Zw.jpeg" /><figcaption>แผนภาพแสดงการทำงานของเครื่องจักรสถานะการทำงาน(state machine) กรณี (a,b) และ b&gt;a</figcaption></figure><p>(0,0)→(3,0)→(0,3)→(3,3)→(1,5)→(1,0)→(0,1)→(3,1)→(0,4)</p><p>การอ่านแผนภาพ คือ การไปทางเฉียงขวา คือ การเติมน้ำจนเต็มเหยือกน้ำเล็กให้นับจำนวนเส้นที่มีระยะ 3 หน่วย(หน่วย คือ แกลลอน)เติมจากว่างเปล่าจนเต็มมีค่าเป็น+1</p><p>การมาจากขวามาซ้าย คือ การเทน้ำออกจากเหยือกใหญ่ 5 หน่วย(หน่วย คือ แกลลอน)เทน้ำออกจากน้ำเต็มจนว่างเปล่า มีค่าเป็น -1</p><p>จากตัวแปรในตำราเรียนของ MIT university เขียนผลรวมเชิงเส้น(Linear combination) ในรูป s(a)+t(b)</p><p>ได้ค่า s = 3(1) (คือ เส้นไปทางเฉียงขวา 3 เส้น)</p><p>t =1(-1) (คือ เส้นมาจากขวามาซ้าย 1 เส้น)</p><p>ค่าของผลรวมเชิงเส้น(Linear combination) = s(a)+t(b) = 3(3)-1(5) = 4</p><p>หากเขียนสมการผลรวมเชิงเส้น(Linear combination euation)</p><p>จะได้ s(3)+t(5) = 4</p><blockquote>ทฤษฏีบทแรกจากเรื่องทฤษฏีจำนวน(Number theory)</blockquote><blockquote>เกี่ยวกับ(Linear combination)</blockquote><p>สมการผลรวมเชิงเส้น(Linear combination euation)ในรูป <strong>s(a)+t(b) = k</strong></p><p>หากมีจำนวนเฉพาะสองจำนวนที่มีค่าต่างกัน(distinct) คือ a และ b โดยที่ a&lt;b โดยที่ a และ b เป็นจำนวนเฉพาะสัมพัทธ์(relatively prime/coprime)ซึ่งกันและกัน นั่น คือ gcd(a,b) = 1 จะมีค่า k ที่ k&lt;b เสมอ โดยขอบเขตของเอกภพสัมพัทธ์ (Relative Universe) คือ เซตของจำนวนเต็ม(Integer)</p><p>อ้างอิง จากภาควิชาคณิตศาสตร์ มหาวิทยาลัย Texas A&amp;M university )</p><p>เพิ่มเติมเรื่องเอกภพสัมพัทธ์โดยผู้เขียนบทความ</p><p>เป็นการคำนวณตามภาพยนต์ ซึ่งมี ค่า k =4 มีค่าต่ำกว่า 5 ทฤษฏีบทแรกจึงเป็นจริง</p><blockquote>แนวทางการแก้ปัญหาเพิ่มเติมและพิสูจน์ทฤษฏีบทแรก</blockquote><p>นอกเหนือจากภาพยนต์สามารถพิสูจน์ทฤษฏีบทนี้ด้วยแผนภาพอีกกรณี คือ เติมเหยือกน้ำ 5 แกลลอนก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jr_nR-VcUTyEsbCcxA-icg.jpeg" /><figcaption>แผนภาพแสดงการทำงานของเครื่องจักรสถานะการทำงาน(state machine) กรณี (b,a) และ b&gt;a</figcaption></figure><p>กำหนดให้เหยือกน้ำใหญ่อยู่ทางด้านขวาในการกำหนดจุดอ้างอิง(reference)ให้แก่เครื่องจักรสถานะการทำงาน(state machine)</p><p>(0,0)→(5,0)→(2,3)→(2,0)→(0,2)→(5,2)→(4,3)→(4,0)</p><p>ได้ค่า s = 5(2) (คือ เส้นไปทางเฉียงขวา 3 เส้น)</p><p>t =3(-2) (คือ เส้นมาจากขวามาซ้าย 1 เส้น)</p><p>จะได้ว่า 5(2)-3(2) = 4 ซึ่งมี ค่า k =4 มีค่าต่ำกว่า 5 ทฤษฏีบทแรกจึงเป็นจริง</p><p>และเครื่องจักรสถานะการทำงาน(state machine)มีการทำงานน้อยกว่า 1 ขั้นตอน</p><blockquote>การแสดงการทำงานเครื่องจักรสถานะการทำงาน(state machine)ด้วยภาษา python</blockquote><p>กรณีการทำงานของเครื่องจักรสถานะการทำงาน(state machine) กรณี (a,b) และ b&gt;a</p><pre>def pour(jug1, jug2):<br>    max1, max2, fill = 3,5, 4  #Change maximum capacity and final capacity<br>    print(&quot;%d\t%d&quot; % (jug1, jug2))<br>    if jug2 is fill:<br>        return<br>    elif jug1 != 0 and jug2 is max2 :<br>        pour(jug1, 0)<br>    elif jug2 is max2:<br>        pour(0, jug1)<br>    elif jug1 != 0 and jug2 is 0:<br>        pour(0, jug1)<br>    elif jug1 is fill:<br>        pour(jug1, 0)<br>    elif jug1 &lt; max1:<br>        pour(max1, jug2)<br>    elif jug1 &lt; (max2-jug2):<br>        pour(0, (jug1+jug2))<br>    else:<br>        pour(jug1-(max2-jug2), (max2-jug2)+jug2)<br> <br>print(&quot;JUG1\tJUG2&quot;)<br>pour(0, 0)</pre><p>ได้ผลลัพธ์(output) คือ</p><pre>JUG1	JUG2<br>0	0<br>3	0<br>0	3<br>3	3<br>1	5<br>1	0<br>0	1<br>3	1<br>0	4</pre><p>การพิสูจน์ทฤษฏีบทแรกเพิ่มเติม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*0UohrVR99i7J6v26trShcg.jpeg" /></figure><p>โจทย์แสดงการคำนวณเพิ่มเติมจากตำราของ MIT University</p><p>เนื่องจากโจทย์ตามภาพยนตร์หาจำนวนเฉพาะสัมพัทธ์ได้ง่าย เพราะ มีจำนวนน้อย</p><p>ทำการตรวจสอบค่า 21 และ 26 ว่าเป็นจำนวนเฉาะสัมพัทธ์(relatively prime)ซึ่งกันและกันหรือไม่ โดยใช้ ภาษา python</p><p>ดังนี้</p><pre>a = 21<br>b = 26</pre><pre>def gcd(a,b): <br>    if(b==0): <br>        return a <br>    else: <br>        return gcd(b,a%b) <br>        <br>print (&quot;The gcd of &quot;+ str(a)+&quot; and &quot;+str(b)+&quot; is : &quot;,end=&quot;&quot;) <br>print (gcd(a,b))</pre><p>ได้ผลลัพธ์(output) คือ</p><pre>The gcd of 21 and 26 is : 1</pre><p>ตรงตามทฤษฏีบทที่1</p><pre>def pour(jug1, jug2):<br>    max1, max2, fill = 21,26, 3  #Change maximum capacity and final capacity<br>    print(&quot;%d\t%d&quot; % (jug1, jug2))<br>    if jug2 is fill:<br>        return<br>    elif jug1 != 0 and jug2 is max2 :<br>        pour(jug1, 0)<br>    elif jug2 is max2:<br>        pour(0, jug1)<br>    elif jug1 != 0 and jug2 is 0:<br>        pour(0, jug1)<br>    elif jug1 is fill:<br>        pour(jug1, 0)<br>    elif jug1 &lt; max1:<br>        pour(max1, jug2)<br>    elif jug1 &lt; (max2-jug2):<br>        pour(0, (jug1+jug2))<br>    else:<br>        pour(jug1-(max2-jug2), (max2-jug2)+jug2)<br> <br>print(&quot;JUG1\tJUG2&quot;)<br>pour(0, 0)</pre><p>ได้ผลลัพธ์(output) คือ</p><pre>JUG1	JUG2<br>0	0<br>21	0<br>0	21<br>21	21<br>16	26<br>16	0<br>0	16<br>21	16<br>11	26<br>11	0<br>0	11<br>21	11<br>6	26<br>6	0<br>0	6<br>21	6<br>1	26<br>1	0<br>0	1<br>21	1<br>0	22<br>21	22<br>17	26<br>17	0<br>0	17<br>21	17<br>12	26<br>12	0<br>0	12<br>21	12<br>7	26<br>7	0<br>0	7<br>21	7<br>2	26<br>2	0<br>0	2<br>21	2<br>0	23<br>21	23<br>18	26<br>18	0<br>0	18<br>21	18<br>13	26<br>13	0<br>0	13<br>21	13<br>8	26<br>8	0<br>0	8<br>21	8<br>3	26<br>3	0<br>0	3</pre><p>พิจารณา สมการผลรวมเชิงเส้น(Linear combination euation)</p><p>ในรูป <strong>s(a)+t(b) = k</strong></p><p>s = 15(1) (การเติมน้ำเหยือกเล็กจนเต็ม)</p><p>t =12(-1) (การเทน้ำออกจากเหยือกใหญ่จนว่างเปล่า)</p><p>จะได้ว่า 21(15)-12(26) = 3 ซึ่งมี ค่า k =3 มีค่าต่ำกว่า 26 ทฤษฏีบทแรกจึงเป็นจริง</p><blockquote>ทฤษฏีบทสองจากเรื่องทฤษฏีจำนวน(Number theory)</blockquote><blockquote>เกี่ยวกับ(Linear combination)</blockquote><p><strong>s(a)+t(b) = k</strong></p><p>ค่าตัวหารร่วมมากของสองจำนวน คือ a และ b หากมีค่ามากกว่า 1 แล้ว ค่าตัวหารร่วมมาก(<strong>greatest common divisor</strong>: <strong>gcd</strong>) ของสองจำนวน a และ b จะเป็นค่าต่ำสุดในเซตจำนวนเต็มบวกของผลรวมเชิงเส้น(Linear combination)ของ a และ b</p><p>เขียนด้วยสัญลักษณ์คณิตศาสตร์ คือ gcd(a,b) &gt; 1</p><p><strong>x(a)+y(b) = </strong>gcd(a,b)</p><p>อ้างอิงทฤษฏีบทสองจากตำรา MIT University</p><p>เพิ่มเติมจากผู้เขียนบทความพิจารณาเฉพาะจำนวนเต็มบวกเท่านั้น เพราะ ค่าตัวหารร่วมมาก(<strong>greatest common divisor</strong>: <strong>gcd</strong>) ไม่นิยามค่าติดลบ</p><p>อ้างอิงค่าจากตำรา MIT University</p><p>เหยือกน้ำสองอันมีปริมาตร 44 และ 52</p><pre>a = 44<br>b = 52</pre><pre>def gcd(a,b): <br>    if(b==0): <br>        return a <br>    else: <br>        return gcd(b,a%b) <br>        <br>print (&quot;The gcd of &quot;+ str(a)+&quot; and &quot;+str(b)+&quot; is : &quot;,end=&quot;&quot;) <br>print (gcd(a,b))</pre><p>ได้ผลลัพธ์(output) คือ</p><pre>The gcd of 44 and 52 is : 4</pre><p>ตรวจสอบทฤษฏีบทสองด้วยเครื่องจักรสถานะการทำงาน(state machine)</p><pre>def pour(jug1, jug2):<br>    max1, max2, fill = 44,52, 4  #Change maximum capacity and final capacity<br>    print(&quot;%d\t%d&quot; % (jug1, jug2))<br>    if jug2 is fill:<br>        return<br>    elif jug1 != 0 and jug2 is max2 :<br>        pour(jug1, 0)<br>    elif jug2 is max2:<br>        pour(0, jug1)<br>    elif jug1 != 0 and jug2 is 0:<br>        pour(0, jug1)<br>    elif jug1 is fill:<br>        pour(jug1, 0)<br>    elif jug1 &lt; max1:<br>        pour(max1, jug2)<br>    elif jug1 &lt; (max2-jug2):<br>        pour(0, (jug1+jug2))<br>    else:<br>        pour(jug1-(max2-jug2), (max2-jug2)+jug2)<br> <br>print(&quot;JUG1\tJUG2&quot;)<br>pour(0, 0)</pre><p>ได้ผลลัพธ์(output) คือ</p><pre>JUG1	JUG2<br>0	0<br>44	0<br>0	44<br>44	44<br>36	52<br>36	0<br>0	36<br>44	36<br>28	52<br>28	0<br>0	28<br>44	28<br>20	52<br>20	0<br>0	20<br>44	20<br>12	52<br>12	0<br>0	12<br>44	12<br>4	52<br>4	0<br>0	4</pre><p>พบว่าทฤษฏีบทสองเป็นจริง</p><blockquote>สรุป</blockquote><p>ผู้เขียนบทความได้พิสูจน์ทฤษฏีบทจำนวน(Number theory)เกี่ยวกับ(Linear combination)จำนวน2ทฤษฏีบทด้วยเครื่องจักรสถานะการทำงาน(state machine)ในขอบเขตจำนวนเต็ม(Integer)</p><p>ทำให้สามารถนำไปวิเคราะห์ต่อได้จากขอบเขตของตัวแปรสองตัวที่ไม่เท่ากันเป็นพื้นฐานนำไปสู่การแก้ปัญหาในเชิงโครงสร้างซับซ้อนต่อไปได้อาจจะนำไปสู่การทำขอบเขตของการชนของระบบเครือข่าย(network)ที่ซับซ้อนได้จากรูปที่ผู้เขียนบทความแสดงให้ดูปัญหาเหยือกน้ำ(Water Jug Problem) ซึ่งสามารถนำไปประยุกต์การใช้งานได้หลากหลายหวังว่าจะเป็นพื้นฐานและเป็นบทความที่มีประโยชน์ต่อไปในอนาคต ขอจบการวิเคราะห์เครื่องจักรสถานะการทำงาน(state machine)ไว้เพียงเท่านี้</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a58ec50e5cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ปัญหาการมอบหมายงาน(assignment problem )ขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm)]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B8%9B%E0%B8%B1%E0%B8%8D%E0%B8%AB%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A1%E0%B8%AD%E0%B8%9A%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%A2%E0%B8%87%E0%B8%B2%E0%B8%99-assignment-problem-%E0%B8%82%E0%B8%B1%E0%B9%89%E0%B8%99%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%A7%E0%B8%B4%E0%B8%98%E0%B8%B5%E0%B8%AE%E0%B8%B1%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99-hungarian-algorithm-426e92f21f1b?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/426e92f21f1b</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[logistics]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Tue, 30 Oct 2018 09:05:02 GMT</pubDate>
            <atom:updated>2018-10-30T09:16:50.424Z</atom:updated>
            <content:encoded><![CDATA[<h3>ปัญหาการมอบหมายงาน(assignment problem)โดยขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm)</h3><p>เป้าหมายของการจัดงาน/มอบหมายงาน(assignment problem)คือ ต้องการ ให้ เกิดการจัดงานที่ดีที่สุด โดยอาจทำให้เกิดต้นทุนในการดำเนินการที่ต่ำที่สุด หรือทำให้เวลาในการทำงานโดยรวมน้อยที่สุดหรือจัดงานให้เกิดกำไรโดยรวมแก่องค์กรมากที่สุด ในการจัดงานให้คนหรือเครื่องจักร</p><p>โดยอยู่ในรูป cost matrix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*tCgXsVXWyako7KNQWSY88w.jpeg" /><figcaption>C = cost matrix</figcaption></figure><p>สามาอธิบายได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/30/1*BlOOJs4ml2FeN6Yjs34rag.jpeg" /><figcaption>เป็นค่าสมาชิกแต่ละตัวโดยที่แถว i และหลัก(สดมภ์) j</figcaption></figure><p>จะมีความสัมพันธ์ระหว่างแถว(row)และหลัก(column)</p><p>ยกตัวอย่าง เช่น แถว คือ ชื่อคนงานแต่ละคน</p><p>หลัก คือ ชนิดของงานที่ทำ</p><p>จะได้ ค่าที่สัมพันธ์ คนงาน และ งานที่ทำเป็น ต้นทุนหรือค่าแรงที่นายจ้างต้องจ่ายให้</p><p>เพื่อคำนวณหาค่าต้นทุนต่ำที่สุดสำหรับองค์กร ในโจทย์ปัญหากรณีทั่วไป</p><p>มีคุณสมบัติที่เห็นได้ชัดเจน คือ 1.เมทริกซ์จตุรัส 2.มีค่าเป็น0หรือค่าบวก</p><blockquote>ขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) แบบลดทอน</blockquote><p>ถูกคิดค้นและตั้งชื่อโดย แฮโรลด์ วิลเลียม คุห์น ในปี ค.ศ. 1955 ขั้นตอนวิธีนี้มีพื้นฐานส่วนใหญ่จากการคิดของนักคณิตศาสตร์ชาวฮังกาเรียน 2 คน คือ Dénes Kőnig และ Jenő Egerváry</p><p>โดยมีขั้นตอนจาก <a href="http://www.hungarianalgorithm.com/hungarianalgorithm.php">HungarianAlgorithm.com</a> เป็นวิธีการลดทอนของขั้นตอนฮังกาเรียนและขอยกตัวอย่างไปพร้อมกันเพื่อให้เข้าใจอย่างถ่องแท้</p><p>โจทย์เป็นความสัมพันธ์ของคนงานและงานที่ทำผลตอบแทนคือค่าแรง</p><p>บริษัทต้องการจ่ายค่าแรงที่ต่ำที่สุด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*o7xhVHcgFgVSJTrQsz2n-A.jpeg" /><figcaption>โจทย์ปัญหาตัวอย่างเป็น cost matrix มิติ 3×3</figcaption></figure><p>โดยที่ คนงานคนที่ 1[Worker 1(W1)]</p><p>คนงานคนที่ 2[Worker 2(W2)]</p><p>คนงานคนที่ 3[Worker 3(W3)]</p><p>Job 1 คือ งานแบบที่ 1</p><p>Job 2 คือ งานแบบที่ 2</p><p>Job 3 คือ งานแบบที่ 3</p><p>ค่าในตาราง คือ ค่าแรงหน่วยเป็น US</p><p><strong>ขั้นตอนที่1</strong></p><p>ให้นำค่าที่ต่ำที่สุดดูตามแนวแถว แต่ละแถวลบตามแนวแถวของแต่ละแถวทั้งหมด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*ZQpInxdMWpYv4Agmt7ycKw.jpeg" /></figure><p>ตัวอย่างการคำนวณของแถวที่ 1 ค่าต่ำสุดตามแนวแถว คือ 10 (มองค่า 10,16,32)</p><p>ให้นำมาลบออกจากสมาชิกทั้งหมดของแถวที่ 1</p><p>ค่าcostของสมาชิกของแถวที่1หลักที่1: 10–10 = 0</p><p>ค่าcostของสมาชิกของแถวที่1หลักที่2: 16–10 = 6</p><p>ค่าcostของสมาชิกของแถวที่1หลักที่2: 32–10 = 22</p><p><strong>คำแนะนำเพิ่มเติมจากผู้เขียนบทความ “โดยแถวที่2ให้นำมาคิดใหม่ทั้งหมดไม่เกี่ยวข้องกับแถวที่ 1”</strong></p><p><strong>ขั้นตอนที่2</strong></p><p>ให้นำค่าที่ต่ำที่สุดดูตามแนวหลัก แต่ละแถวลบตามแนวหลักของแต่ละหลักทั้งหมด</p><p>คำแนะนำเพิ่มเติมจากผู้เขียนบทความ <strong>“ให้นำ cost matrix ที่ได้จากขั้นตอนที่1นำมาทำต่อเท่านั้น เพราะ เป็นการการะทำต่อเนื่อง”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*nagirsQ9KG4lcLcmpuzSEw.jpeg" /></figure><p>ตัวอย่างการคำนวณของหลักที 2 ค่าต่ำสุดตามแนวหลัก คือ 2 (มองค่า 6,8,2)</p><p>ให้นำมาลบออกจากสมาชิกทั้งหมดของหลักที่ 2</p><p>ค่าcostของสมาชิกของหลักที่2แถวที่1: 6–2 = 4</p><p>ค่าcostของสมาชิกของหลักที่2แถวที่2: 8–2 = 6</p><p>ค่าcostของสมาชิกของหลักที่2แถวที่2: 2–2 = 0</p><p><strong>คำแนะนำเพิ่มเติมจากผู้เขียนบทความ “โดยแถวที่2ให้นำมาคิดใหม่ทั้งหมดไม่เกี่ยวข้องกับแถวที่ 1”</strong></p><p><em>ข้อสังเกตุจากผู้เขียนบทความ กรณีที่ค่าต่ำสุดเกิดเป็น0 เช่น กรณีของหลักที่1</em></p><p><em>นั่นคือ การค่า 0 ไปลบออกจากทั้งหมดตามแนวหลัก ทำให้เกิดค่าเท่าเดิมตลอดทั้งแนวหลัก “</em><strong>จึงละการกระทำได้หากเกิดค่าต่ำสุดเป็น 0</strong><em>” และยังคงจริงในขั้นตอนที่ 1 เช่นกัน</em></p><p><strong>ขั้นตอนที่ 3</strong></p><p>3.1 ทำการคลุม[อธิบายตามผู้เขียนบทความขอใช้คำว่าทำเครื่องหมาย(mark)ไว้]เลข 0 โดยใช้เส้นกำกับไว้ตามแนวตั้งและแนวนอน โดยใช้จำนวนเส้นให้ต่ำที่สุด</p><p>คำแนะนำเพิ่มเติมจากผู้เขียนบทความ <strong>“เลือกแนวที่มีค่า 0 มากกว่า 1 ค่าก่อน และเพื่อป้องกันความสับสนให้ทำการตรวจสอบค่า(scan)จากแนวหลักก่อนแล้วจึงการตรวจสอบค่า(scan)ตามแนวนอน”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*NAbuOSl_r9WFQS_nF4W2Sg.jpeg" /></figure><p>3.2 ทำการตรวจสอบ<strong> “จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix”</strong></p><p>จึงจะเกิด <strong>“การมอบหมายงานที่เหมาะสม”</strong> (optimal assignment)</p><p>ในกรณีนี้ จำนวนเส้น = 2</p><p>จำนวนแถวหรือหลักของมิติของ cost matrix = 3</p><p>ยังไม่เกิด การมอบหมายงานที่เหมาะสม(optimal assignment)</p><p>ให้ไปทำขั้นตอนที่4</p><p>หาก <strong>จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix</strong></p><p>ให้ทำการหยุดขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) เพราะ เกิดการมอบหมายงานที่เหมาะสม(optimal assignment)</p><p><strong>ขั้นตอนที่4</strong></p><p>ให้การพิจารณาค่าทั้งหมดจาก cost matrix ขั้นตอนที่ 3ที่ค่าที่ไม่ได้คลุม(mark)ไว้</p><p>ในที่นี้ คือ 4,10,6 และ 14 ให้เลือกค่าที่ต่ำที่สุด คือ 4</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*r5ri4i0Fre8Bg8Tu7A9kzA.jpeg" /></figure><p>4.1 ให้นำค่าต่ำสุดจากค่าทั้งหมดจากค่าที่ไม่ได้คลุม(mark)ไว้มาลบออกจากค่าที่ไม่ได้คลุม(mark)ไว้ทั้งหมด</p><p>4.2ให้นำค่าต่ำสุดจากค่าทั้งหมดจากค่าที่ไม่ได้คลุม(mark)ไว้มาบวก จุดที่ค่าที่คลุม(mark)ไว้สองครั้ง เกิดที่แถวที่3หลักที่1</p><p><strong>คำแนะนำเพิ่มเติมจากผู้เขียนบทความ เพิ่มเติมจาก website</strong></p><p><strong>ให้กลับไปทำขั้นตอนที่ 3 เพื่อพิจารณาค่าการมอบหมายงานที่เหมาะสม(optimal assignment)ใหม่</strong></p><p><strong>การคลุม(mark) คือ การกระทำใหม่ไม่เกี่วข้องกับการคลุมจากครั้งที่แล้ว</strong></p><p>นั่น คือ</p><p><em>ขั้นตอนที่ 3(รอบที่ 2)</em></p><p>3.1 ทำการคลุม(mark) ให้ดูรูปด้านบน</p><p>จำนวนเส้น = 3</p><p>จำนวนแถวหรือหลักของมิติของ cost matrix = 3</p><p>3.2 ทำการตรวจสอบ</p><p><strong>จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix</strong></p><p>ให้ทำการหยุดขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) เพราะ เกิดการมอบหมายงานที่เหมาะสม(optimal assignment)</p><blockquote>สรุป</blockquote><p>ค่า การมอบหมายงานที่เหมาะสม(optimal assignment) จาก ขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm)</p><p>ทำโดยการจุดที่เลือกค่า 0 ไว้นำกลับไปพิจารณาจากcost matrix ค่าจริงก่อนโดนลดทอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*bSq_0oK-LFB8DEQJTfA9WQ.jpeg" /></figure><p>จะเกิดค่าแรงต่ำที่สุด = 14+16+34 = 64 US</p><p>นั่น คือ คนงานคนที่ 1[Worker 1(W1)] จะทำงานแบบที่ 2(Job2)</p><p>คนงานคนที่ 2[Worker 2(W2)] จะทำงานแบบที่ 1(Job1)</p><p>คนงานคนที่ 3[Worker 3(W3)] จะทำงานแบบที่ 3(Job3)</p><p>จะเกิดค่าจ้างที่ต่ำที่สุด ซึ่งเกิดประโยชน์ต่อบริษัท</p><p>จากการมอบหมายงาน(assignment) ที่เป็นไปได้ 3! = 3×2×1 = 6 รูปแบบ</p><p>ผู้เขียนบทความได้ ทำการตรวจสอบจาก website HungarianAlgorithm.com</p><p>โดยเข้าไป [<a href="http://www.hungarianalgorithm.com/solve.php?c=10-16-32--14-22-40--22-24-34">ตัวอย่างการคำนวณ</a>]</p><p>จะแตกต่างในการคลุม(mark) ใน website ทำการคลุมตามแนวนอน</p><p>แต่ผู้เขียนบทความคลุมตามแนวตั้งให้คำตอบตรงกัน สามารถทำได้ทั้งสองวิธี</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*RDiljivkowo4IpQ99MQBkA.jpeg" /></figure><blockquote>ขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) แบบปรกติ</blockquote><p>เอกสารการสอนของภาควิชาคณิตศาสตร์จาก Harvard university [<a href="http://www.math.harvard.edu/archive/20_spring_05/handouts/assignment_overheads.pdf">เอกสาร</a>]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*S7Kx-8sPk1p7W024yRlfzA.jpeg" /><figcaption>โจทย์ตัวอย่าง cost matrix มิติ 3×3</figcaption></figure><p>พนักงานขายต้องการไปที่โรงงานของเล่นด้วยการโดยสารเครื่องบิน จากเมืองหนึ่งไปเมืองหนึ่ง ค่าในตาราง คือ ค่าตั๋วเครื่องบิน(หน่วยเป็น US) ทาบริษัทของพนักงานขายต้องการจ่ายค่าเครื่องบินในราคาต่ำที่สุด</p><p>โดยทำการอธิบายไว้ 5 ขั้นตอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*vWPQ_3njzXF65vgOP-maOw.jpeg" /></figure><p>หากเทียบวิธีการจาก <a href="http://www.hungarianalgorithm.com/hungarianalgorithm.php">HungarianAlgorithm.com</a></p><p>จะพบว่า ขั้นตอนที่ 1 และ ขั้นตอนที่ 2 จะเหมือนกัน</p><p>ขั้นตอนที่ 3 และ 4 คือ ขั้นตอน 3 จาก <a href="http://www.hungarianalgorithm.com/hungarianalgorithm.php">HungarianAlgorithm.com</a> และเหมือนกัน</p><p><strong>ขั้นตอนที่ 5 คือ ขั้นตอนที่ 4 จาก </strong><a href="http://www.hungarianalgorithm.com/hungarianalgorithm.php"><strong>HungarianAlgorithm.com</strong></a><strong> มีความแตกต่างกัน</strong></p><p>และ<strong>มีการแนะนำให้กลับไปขั้นตอนที่ 3 ตามที่ผู้เขียนบทความเคยแนะนำไว้</strong></p><p>ผู้เขียนบทความจะขอทำเป็น 4 ขั้นตอนตามเดิมเพื่อป้องกันความสับสน</p><p><strong>ขั้นตอนที่ 1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*SzdBlZZOCFBZl8UQikFxuQ.jpeg" /></figure><p><strong>ขั้นตอนที่ 2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*_T4BN44ChXttYYC71Uy76Q.jpeg" /></figure><p><strong>ขั้นตอนที่ 3</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*_CKO-luGUtNdb1PKeg9ckw.jpeg" /></figure><p>3.1 ทำการคลุม(mark)</p><p>3.2 ทำการตรวจสอบ</p><p><strong>จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix หรือไม่</strong></p><p>ในที่นี้ จำนวนเส้น = 3</p><p>จำนวนแถวหรือหลักของมิติของ cost matrix = 3</p><p>ให้ทำการหยุดขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) เพราะ เกิดการมอบหมายงานที่เหมาะสม(optimal assignment)</p><blockquote>สรุป</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/171/1*uZ_3b9ysx5RmgHfMxwet5A.jpeg" /></figure><p>ทำการเลือกค่า0ไว้โดยไม่ให้ตรงกันและนำกลับไปพิจารณาจากcost matrix ค่าจริงก่อนโดนลดทอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*LUCTceKQGMg48Ib4tuEjcw.jpeg" /></figure><p>จะได้ ค่าตั๋วเครื่องบินที่ถูกที่สุด = 200+400+350 = 950 US</p><p>เขียนบทความได้ ทำการตรวจสอบจาก website HungarianAlgorithm.com</p><p>โดยเข้าไป [<a href="http://www.hungarianalgorithm.com/solve.php?c=250-400-350--400-600-350--200-400-250">ตัวอย่างการคำนวณ</a>] พบว่าได้ cost matrix ลดทอนเท่ากัน</p><p>แตกต่างเพียงการคลุม(mark)เพียงเท่านั้นดังภาพ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*GdZR7RSzPwTdKhVNgm52wA.jpeg" /></figure><p>เนื่องจากยังไม่ถึงขั้นตอนที่ 4 ที่ไม่เหมือนกันจึงยกตัวอย่างอีกข้อหนึ่ง โดยอ้างอิงตัวอย่างจาก <a href="https://brilliant.org/wiki/hungarian-matching/">BRILLIANT</a> ซึ่งแสดงการคำนวณ เช่นเดียวกับ Harvard university</p><p>แต่ไม่ได้เขียนความสัมพันธ์ระหว่างสองตัวแปรไว้ให้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*c-Ip4oe_mutOvIyeLksSHg.png" /><figcaption>โจทย์ตัวอย่าง cost matrix มิติ 3×3</figcaption></figure><p><strong>ขั้นตอนที่ 1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*jIpT4z_A2CCFMe0zUaZwCg.png" /></figure><p><strong>ขั้นตอนที่ 2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*f1gaj_mxc9G907IhOfwfvA.png" /></figure><p><strong>ขั้นตอนที่ 3</strong></p><p>3.1 ทำการคลุม(mark)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*zqwZ5_FtxywaNKmu69zsBw.png" /></figure><p>3.2 ทำการตรวจสอบ</p><p><strong>จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix </strong>หรือไม่</p><p>จำนวนเส้น = 2</p><p>จำนวนแถวหรือหลักของมิติของ cost matrix = 3</p><p>ยังไม่เกิด การมอบหมายงานที่เหมาะสม(optimal assignment)</p><p>ให้ไปทำขั้นตอนที่4</p><p><strong>ขั้นตอนที่4</strong></p><p>มีความแตกต่างผู้เขียนบทความจึงขออธิบายอย่างละเอียด</p><p>ให้การพิจารณาค่าทั้งหมดจาก cost matrix ขั้นตอนที่ 3ที่ค่าที่ไม่ได้คลุม(mark)ไว้</p><p>ในที่นี้ คือ 17,2,26 และ 88 ให้เลือกค่าที่ต่ำที่สุด คือ 2</p><p>4.1 ให้นำค่าต่ำสุดจากค่าทั้งหมดจากค่าที่ไม่ได้คลุม(mark)ไว้มาลบออกจากแถวค่าที่ไม่ได้คลุม(mark)ไว้ทั้งหมดทั้งแถว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*Lk09HA03M6uSlz0B-nOgnA.png" /><figcaption>ลบ2ออกจากแถว1และแถว3ทั้งแถว</figcaption></figure><p>4.2 ให้นำค่าต่ำสุดจากค่าทั้งหมดจากค่าที่ไม่ได้คลุม(mark)ไว้มาบวก หลักที่คลุม(mark)เฉพาะแนวหลัก เกิดที่แถวที่3หลักที่1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*8djvzTv4eGQfdWTQWViBZg.png" /><figcaption>บวก2ที่หลักที่1ทั้งหลัก</figcaption></figure><p><strong>ให้กลับไปทำขั้นตอนที่ 3 เพื่อพิจารณาค่าการมอบหมายงานที่เหมาะสม(optimal assignment)ใหม่</strong></p><p><strong>การคลุม(mark) คือ การกระทำใหม่ไม่เกี่วข้องกับการคลุมจากครั้งที่แล้ว</strong></p><p>นั่น คือ</p><p><em>ขั้นตอนที่ 3(รอบที่ 2)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*32HQI6kvO75kPri4Y0n0lg.png" /></figure><p>3.1 ทำการคลุม(mark) ให้ดูรูปด้านบน</p><p>จำนวนเส้น = 3</p><p>จำนวนแถวหรือหลักของมิติของ cost matrix = 3</p><p>3.2 ทำการตรวจสอบ</p><p><strong>จำนวนเส้น = จำนวนแถวหรือหลักของมิติของ cost matrix</strong></p><p>ให้ทำการหยุดขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) เพราะ เกิดการมอบหมายงานที่เหมาะสม(optimal assignment)</p><blockquote>สรุป</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*l3W9mDmQMGo1xhP0_HCH0w.png" /></figure><p>ทำการเลือกค่า0ไว้โดยไม่ให้ตรงกันและนำกลับไปพิจารณาจากcost matrix ค่าจริงก่อนโดนลดทอน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*YpZDLq_gpVKk7gUyvfV4hQ.png" /></figure><p>จะเกิดค่าที่ต่ำที่สุด = 122+135+150 = 407</p><p>ผู้เขียนบทความได้ ทำการตรวจสอบจาก website HungarianAlgorithm.com</p><p>โดยเข้าไป [<a href="http://www.hungarianalgorithm.com/solve.php?c=108-125-150--150-135-175--122-148-250">ตัวอย่างการคำนวณ</a>] พบว่าได้ cost matrix ลดทอนเท่ากัน</p><p>แตกต่างเพียงการคลุม(mark)เพียงเท่านั้นดังภาพ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*bdg6ItT_cZYsYHVsJx_2rw.jpeg" /></figure><blockquote>สรุปจากความคิดเห็นของผู้เขียนบทความ</blockquote><p>จากวิธีการของภาควิชาคณิตศาสตร์จาก Harvard university ทำให้เห็นได้ชัดเจนว่าขั้นตอนวิธีฮังกาเรียน (Hungarian Algorithm) แบบลดทอน นั้นความจริง คือ การแก้สมการเชิงเส้น(linear algebra)ในรูปแบบเมทริกซ์ปรกติ เพียงแต่ลดขั้นตอนเพื่อลดเวลาเท่านั้น</p><p>วิธีการของภาควิชาคณิตศาสตร์จาก Harvard university จึงเป็นเหมือนการพิสูจน์ที่มาของขั้นตอนวิธีฮังกาเรียน(Hungarian Algorithm)รูปแบบทั่วไปที่นิยมแพร่หลายที่ผู้เขียนบทความเรียกว่าการลดทอน เกิดการคืนกลับค่าเดิมในบางส่วนจึงละเว้นการคำนวณเกิดวิธีการใหม่ขึ้นมาได้</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=426e92f21f1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[วิทยาการเข้ารหัสลับ(Cryptography)]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B8%A7%E0%B8%B4%E0%B8%97%E0%B8%A2%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2%E0%B8%A3%E0%B8%AB%E0%B8%B1%E0%B8%AA%E0%B8%A5%E0%B8%B1%E0%B8%9A-cryptography-b7b7a3746e40?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7b7a3746e40</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Sun, 28 Oct 2018 18:10:28 GMT</pubDate>
            <atom:updated>2018-10-29T01:32:11.033Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cryptography</h3><p>มีรากศัพท์มาจากภาษากรีก <em>kryptos</em> แปลว่า ซ่อน และ <em>graphein</em> แปลว่า การเขียน</p><p>เขียนในนิยามได้ดังนี้ คือ</p><p>“การเข้าและถอดรหัสข้อมูล เป็นขั้นตอนหนึ่งสำหรับ การรักษาข้อมูลให้มีความลับ”</p><p>โดยป้องกันความลับโดยการเข้ารหัสลับด้วยกุญแจ(Key)สองวิธี ดังนี้</p><blockquote><em>1.การเข้ารหัสลับแบบกุญแจสมมาตร(Symmetric Cryptography)</em></blockquote><p>สามารถเรียกกระบวนการถอดรหัสว่า <strong>Secret Key Algorithm</strong> หรือ <strong>S<em>ymmetric</em></strong></p><p><strong>Algorithm </strong>เป็นวิธีการ “<strong>เข้ารหัส(encrypt)” </strong>และ “<strong>ถอดรหัส(decrypt)”</strong></p><p>โดยใช้ “<strong>รหัสลับ(key)”</strong> เดียวกันและมีความยาวคงที่</p><p><strong><em>[secret-key, single-key, shared-key, one-key, และ private-key</em></strong></p><p><strong><em>คือ คำอื่นๆที่สามารถเจอได้และมีความหมายเหมือนกัน]</em></strong></p><p>algorithm ที่รู้จักอย่างแพร่หลาย คือ Data Encryption Standard (<a href="https://searchsecurity.techtarget.com/definition/Data-Encryption-Standard">DES</a>)</p><p>จาก <strong>กระทรวงกลาโหมสหรัฐ (</strong>United States Department of Defense : DoD)</p><p>เป็น algorithm ที่พัฒนาโดย IBM เมื่อปี 1977</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*-r60A_IgsRmHuFbCgAbrMw.jpeg" /><figcaption><em>การเข้ารหัสลับแบบกุญแจสมมาตร(Symmetric Cryptography)</em></figcaption></figure><p>ตัวอย่างการคำนวณจากหนังสือ</p><p>“H. Katzan, The Standard Data Encryption Algorithm, pp75–94, Petrocelli Books Inc., New York, 1977”</p><pre>Key:        5B5A57676A56676E<br>Plaintext:  675A69675E5A6B5A<br>Ciphertext: 974AFFBF86022D1F</pre><p>แสดงการคำนวณได้โดย</p><pre>setKey(5b5a57676a56676e)<br><br>encryptDES(675a69675e5a6b5a)<br>  IP:	L0=ffb2194d, R0=004df6fb<br>  Rnd1	f(R0=004df6fb,  SK 1=38 09 1b 26 2f 3a 27 0f ) = 746fc91a<br>  Rnd2	f(R1=8bddd057,  SK 2=28 09 19 32 1d 32 1f 2f ) = 7add38ae<br>  Rnd3	f(R2=7a90ce55,  SK 3=39 05 29 32 3f 2b 27 0b ) = a5e3f499<br>  Rnd4	f(R3=2e3e24ce,  SK 4=29 2f 0d 10 19 2f 1d 3f ) = c5403e1c<br>  Rnd5	f(R4=bfd0f049,  SK 5=03 25 1d 13 1f 3b 37 2a ) = 91a62c82<br>  Rnd6	f(R5=bf98084c,  SK 6=1b 35 05 19 3b 0d 35 3b ) = 6aeb6bc3<br>  Rnd7	f(R6=d53b9b8a,  SK 7=03 3c 07 09 13 3f 39 3e ) = 1e9f7513<br>  Rnd8	f(R7=a1077d5f,  SK 8=06 34 26 1b 3f 1d 37 38 ) = 59d1851c<br>  Rnd9	f(R8=8cea1e96,  SK 9=07 34 2a 09 37 3f 38 3c ) = 0fc4b474<br>  Rnd10	f(R9=aec3c92b,  SK10=06 33 26 0c 3e 15 3f 38 ) = 8de55e67<br>  Rnd11	f(R10=010f40f1, SK11=06 02 33 0d 26 1f 28 3f ) = dced7991<br>  Rnd12	f(R11=722eb0ba, SK12=14 16 30 2c 3d 37 3a 34 ) = 898d0def<br>  Rnd13	f(R12=88824d1e, SK13=30 0a 36 24 2e 12 2f 3f ) = 34cee3c3<br>  Rnd14	f(R13=46e05379, SK14=34 0a 38 27 2d 3f 2a 17 ) = 6a4754b1<br>  Rnd15	f(R14=e2c519af, SK15=38 1b 18 22 1d 32 1f 37 ) = 5bac9dc6<br>  Rnd16	f(R15=1d4ccebf, SK16=38 0b 08 2e 3d 2f 0e 17 ) = e448c462<br>  FP:	L=974affbf, R=86022d1f<br> returns 974affbf86022d1f<br><br>974affbf86022d1f</pre><p>สามารถเข้าได้ที่ <a href="https://www.emvlab.org/descalc/?key=5B5A57676A56676E&amp;iv=0000000000000000&amp;input=974AFFBF86022D1F&amp;mode=ecb&amp;action=Decrypt&amp;output=974AFFBF86022D1F">emvlab.org</a> มีโปรแกรมจำลองให้ได้ตรวจทานคำตอบ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*MyMQCOdLb70mgF7ZgWSW9A.jpeg" /></figure><p>จะพบว่าการคำนวณในหนังสือนั้นเป็นแบบ ECB ซึ่งเป็นกระบวนการพื้นฐาน</p><h4><strong>ข้อดีข้อเสียของ Data Encryption Standard(DES)</strong></h4><p>ข้อดี : รวดเร็ว</p><p>ข้อเสีย : algorithm ถูกเปิดเผยและใช้ key ตัวเดียวกันจึงสามารถถอดรหัสได้โดยง่าย</p><h4>Data Encryption Standard(DES) แบ่งได้ 2 ประเภทที่นิยม</h4><p>1.Stream Ciphers</p><p>การใช้ค่าจากฟังก์ชั่น pseudo random number generator (PRNG) เข้ารหัสทีละ bit, byte หรือ word มีข้อเสีย คือ การส่งต่อความผิดพลาด (Error Propagation) หากส่ง ข้อมูลผิดพลาด 1 บิต ก็จะทำให้ข้อมูลที่เหลือของฝ่ายรับผิดไปทั้งหมด</p><p>2.Block Ciphers</p><p>ผลลัพธ์ข้อมูล(output)ที่เข้ารหัสจะมีขนาดเท่ากับข้อมูลที่ป้อนเข้ามา(input)</p><p>Electronic Code Book(ECB) เป็นกระบวนพื้นฐานสำหรับวิธีนี้</p><p>ภาพกระบวนการ Electronic Code Book(ECB)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*03BfQgtpQWi2M63Tf5vffA.png" /><figcaption>การเข้ารหัสลับแบบ Electronic Code Book (ECB)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*QG2iQfJOdpoL4CpMDm440w.png" /><figcaption>การถอดรหัสลับแบบ Electronic Code Book (ECB)</figcaption></figure><p>เพื่อให้ข้อมูลทุก block แตกต่างกันออกไปอย่างแท้จริง มีการเสนอกระบวนการ Cipher Block Chaining (CBC) และ Cipher Feedback (CFB) ขึ้นมา โดยหลักการแล้วทั้งสองแบบคล้ายกันคือใช้ข้อมูลที่เข้ารหัสแล้วของ Block ก่อนหน้าเพื่อเป็นส่วนประกอบของ Key เข้ารหัสของ block ถัดไป กระบวนการเช่นนี้ทำให้แม้จะส่งข้อมูลเดิมซ้ำๆ ไปเรื่อยๆ ข้อมูลที่ถอดรหัสแล้วก็จะเปลี่ยนไปไม่รู้จบ</p><p>ภาพประกอบ Cipher Block Chaining (CBC)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*IAFxh1Y-R6GUVcuHGsi-QA.png" /><figcaption>การเข้ารหัสลับแบบ Cipher Block Chaining (CBC)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*wmhntqCrfcji-r-4kKPzbA.png" /><figcaption>การถอดรหัสลับแบบ Cipher Block Chaining (CBC)</figcaption></figure><p>ภาพประกอบ Cipher Feedback(CFB)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*U4ktMDXCMZUnjklAwoJ1lA.png" /><figcaption>เป็นการเข้ารหัสลับแบบ Cipher Feedback(CFB)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*4ey6fRNzcFs9efcNhf3psQ.png" /><figcaption>การถอดรหัสลับแบบ Cipher Feedback(CFB)</figcaption></figure><p>ปัญหาของทั้ง CBC และ CFB คือหากมี block ใด block หนึ่งเสียหายไประหว่างทาง ฝั่งถอดรหัสจะไม่สามารถถอดรหัส block ถัดไปได้อีกด้วย ทำให้ข้อมูลเสียหายไปพร้อมกัน 2 block แต่ใช้ block ถัดไปที่ได้รับถูกต้องแต่ไม่สามารถถอดรหัสได้เพื่อไปคำนวณกุญแจสำหรับอีก 2 block ถัดจาก block ที่เสียหายได้ ข้อจำกัดอีกประการ คือ CBC และ CFB นั้นไม่สามารถเข้ารหัสแบบขนานได้สะดวก เพราะ แต่ละ block ต้องรอ block ก่อนหน้าเสมอ ทำให้การกระจายงานใน CPU หลายคอร์ทุกวันนี้ทำได้ยาก</p><blockquote>2.การเข้ารหัสแบบกุญแจอสมมาตร(Asymmetric Cryptography)</blockquote><p>ปัญหาของการเข้ารหัสแบบ Secret Key Algorithm คือ การแลกเปลี่ยน Key ที่ใช้ใน เชิงปฏิบัติได้ยาก</p><p>จึงมีการพัฒนาเทคนิคการแจกจ่าย Key อย่างปลอดภัย โดยใช้ Key ที่ เข้ารหัสและถอดรหัสคนละ Key โดยที่มีความสัมพันธ์กันเชิงคณิตศาสตร์</p><p>เรียกว่าวิธี <strong>Public-key cryptography </strong>หรือ <strong>Public/private key cryptography</strong></p><p>ถูกอธิบายครั้งแรกในปี 1976 โดย มาร์ติน เฮลล์แมน (Martin Hellman) และวิทฟิลด์</p><p>ดิฟฟี(Whitfield Diffie) แห่ง <strong>Stanford University</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*tWLrg5aijvJ3oG9aVGX_LA.jpeg" /><figcaption>การเข้ารหัสแบบกุญแจอสมมาตร(Asymmetric Cryptography)</figcaption></figure><p>โดยที่</p><p>“<strong>Public Key” </strong>เป็น Key ที่ประกาศให้สาธารณะทราบ ใครจะนำไปใช้ก็ได้</p><p>= (n,e)</p><p>“<strong>Private Key</strong>” เป็น Key ที่รู้เฉพาะเจ้าของ</p><p>=(n,d)</p><p>Public Key สร้าง”<strong>กุญแจคู่(Key-Pair)”</strong> โดยอาศัยทฤษฎี One-way Function ซึ่งเป็นฟังก์ชั่นทางคณิตศาสตร์ที่คำนวณค่าได้ ง่าย แต่คำนวณในทางตรงกันข้ามได้ยากมาก</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*jd8M_WAiqcg5GoTrV4icGA.jpeg" /></figure><p>algorithm ที่รู้จักอย่างแพร่หลาย คือ RSA algorithm มาจากชื่อของผู้คิด algorithm นี้ คือ Revest, Shamir และ Adlemen จากมหาวิทยาลัย Massachusetts Institute of Technology(MIT) โดยชื่อมาจากตัวอักษรตัวแรกของชื่อของทั้งสามท่านที่คิดค้นร่วมกัน</p><p>RSA algorithm</p><p>จาก DI Management Services บริษัทให้คำปรึกษาทางด้านคอมพิวเตอร์ ในประเทศออสเตรเลีย อธิบายไว้ในส่วน <a href="https://www.di-mgt.com.au/rsa_alg.html">RSA algorithm</a> อธิบายได้โดยย่อดังนี้</p><h4>ขั้นตอนที่ 1</h4><p>n= p×q โดยที่ p และ q เป็นจำนวนเฉพาะที่แตกต่างกัน (distinct primes)</p><p>เพิ่มเติมจากผู้เขียนบทความยิ่งมีค่ามากยิ่งดี และนิยมใช้ค่า 1024 bits</p><h4>ขั้นตอนที่ 2</h4><p><em>φ</em>(<em>n</em>) = (p−1)×(q−1) หรือ</p><p><em>ϕ</em>(<em>n</em>) = (p−1)×(q−1)</p><p>เพิ่มเติมจากผู้เขียนบทความ <em>φ</em>(n) คือ ฟังก์ชั่น euler’s totient function</p><p>เป็นฟังก์ชั่นที่หาความสัมพันธ์ระหว่าง n (คงที่) และ จำนวนบวกตั้งแต่ 1 ถึง n ว่าเป็นจำนวนเฉพาะสัมพัทธ์(coprime,co-prime หรือ relatively prime) ซึ่งกันและกันหรือไม่</p><p>ยกตัวอย่าง เช่น <em>φ</em>(9) = 6</p><p>เป็นการนับจำนวนบวก(positive integer number) ในช่วง 1–9 ว่ามีกี่ตัว ที่เป็นจำนวนเฉพาะสัมพัทธ์กับ 9 (มีค่าคงที่)</p><p>ไม่เอาเลข 3,6,9 เพราะ gcd(9, 3) = gcd(9, 6) = 3</p><p>และ gcd(9, 9) = 9</p><p>จึงมีทั้งสิ้น 6 ตัว คือ 1,2,4,5,7 และ 8 ซึ่งมีคุณสมบัติ gcd(n,x) = 1 ซึ่งเป็นคุณสมบัติของจำนวนเฉพาะสัมพัทธ์ โดยที่ x อยู่ในช่วง 1 ถึง 9</p><h4>ขั้นตอนที่3</h4><p>เลือกค่า e (ชื่อเต็ม public exponent)</p><p>โดยมีเงื่อนไข e &lt; nและ gcd(e,<em>φ</em>(n))=1</p><p>เพิ่มเติมจากผู้เขียนบทความ คือ e และ <em>φ(n)</em> มี ห.ร.ม. = 1</p><p>หรือกล่าวได้ว่า e และ <em>φ(n)</em> เป็นจำนวนเฉพาะสัมพัทธ์(coprime หรือ relatively prime) ซึ่งกันและกัน</p><h4>ขั้นตอนที่ 4</h4><p>d×e = 1 mod ϕ</p><p>หรือ d = (1/e) mod ϕ</p><p>เพิ่มเติมจากผู้เขียนบทความ ในขั้นตอนนี้จะใช้หลักการ</p><p>Extended Euclidean algorithm ซึ่งนำไปสู่ montgomery product ก็คือ การทำ inverse modulation นั่นเอง</p><h4>ขั้นตอนที่ 5</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*-dhiDjho6h8wcbXf7KEnvg.png" /></figure><p>โดยที่ 1&lt;m&lt; n</p><h4>ขั้นตอนที่ 6</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*rwi9TErM-bMccfnPD35qTA.png" /></figure><p>สามารถเข้าได้ที่ <a href="https://www.cs.drexel.edu/~jpopyack/IntroCS/HW/RSAWorksheet.html">RSA Calculator</a> จัดทำโดย Drexel University มีโปรแกรมจำลองให้ได้ตรวจทานคำตอบ</p><p>แต่จะมีกระบวนการที่แตกต่างออกจากวิธีปกติ</p><p>เนื่องจากต้องกรอกค่า จึงกำหนด n = 33 เพื่อทำการใส่ค่าเป็นตัวอย่าง</p><h4>ขั้นตอนที่1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOcYFpnVyRPmIa_NAmITGA.png" /></figure><p>กำหนดให้ค่า p =3 และ q = 11</p><p>และ candidate มาจากค่าต่างๆที่เป็น คอนกรูเอนซ์(congruence)ร่วมกัน</p><p>และสามารถทำไปพิสูจน์ทฤษฏีของออยเลอร์ได้</p><p><strong>Euler’s theorem</strong> หรือชื่ออื่น <strong>Fermat–Euler theorem,</strong> <strong>Euler’s totient theorem</strong></p><p>แต่มีความหมายเดียวกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*99NMiHTTr3vFI_CXbDXFYg.png" /></figure><p>ซึ่งได้นำมาจากการการรวมกันของ Fermat’s little theorem และ Carmichael’s theorem.</p><p><em>หมายเหตุ</em> <em>φ(n) </em>ในการคำนวณนี้ คือ ค่า r และ candidate ในที่นี้ คือ ค่า K ในขั้นตอนถัดไป</p><h4>ขั้นตอนที่2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*F89Y42ojdESemdKK9T_auw.png" /></figure><p>เลือก candidate มาหนึ่งค่า ทำการแยกตัวประกอบ ในที่นี้ K =d×e</p><p>หากเลือกมาแล้วใช้ไม่ได้จะขึ้นว่า is prime ซึ่งเป็นจำนวนเฉพาะไม่สามารถแยกตัวประกอบได้</p><h4>ขั้นตอนที่ 3</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cuuz3h2yBnJBVI1B6kt1Vw.png" /></figure><p>ทำการตรวจสอบ 3 เงื่อนไข</p><p>1. e*d mod r = 1</p><p>2. ขึ้นข้อความ e and r are relatively prime(e และ r เป็นจำนวนเฉพาะสัมพัทธฺ์ซึ่งกันและกัน)</p><p>3.ขึ้นข้อความ d and r are relatively prime(d และ r เป็นจำนวนเฉพาะสัมพัทธฺ์ซึ่งกันและกัน)</p><p>หากตรงกับเงื่อนไขทั้ง 3 ให้ไปขั้นตอนถัดไป</p><h4>ขั้นตอนที่4</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnAVRQGr-7Lbf8-BT7L2Pg.png" /></figure><p>ทำการใส่ข้อความ ก็จะเห็นการเข้ารหัสและถอดรหัสด้วย Key ทั้ง 2 แบบ</p><p>หมายเหตุ ค่า e และ d ใน กรณีนี้สลับกันได้ไม่ผิดแต่จะต่างกันที่ ciphertext เพียงเท่านั้น เพราะ ยังคงตรงเงื่อนไขอยู่ ทำให้สามารถสรุปได้ว่าจำนวนเฉพาะสองตัวที่มีค่าต่างกัน สามารถสร้าง key-pair ได้มากกว่า 1 คู่ มีความเป็นได้อย่างแน่นอน</p><p>ในบทความนี้มีจุดประสงค์เพื่อให้ได้เข้าใจกระบวนการการเข้ารหัสลับรูปแบบต่างๆที่นิยมและแพร่หลาย ในภาพรวม การวิเคราะห์การทำงานอย่างเจาะลึกต้องอาศัยคณิตศาสตร์ขั้นสูงหากมีโอกาสจะเขียนพิสูจน์ทฤษฎีคณิตศาสตร์ต่างๆที่ประกอบมารวมเป็นวิทยาการเข้ารหัสลับ เพื่อให้บุคคลที่สนใจทางด้านวิทยาการเข้ารหัสลับได้นำไปต่อยอดในด้านต่างๆ ขอจบการอธิบายภาพรวมเพียงเท่านี้</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7b7a3746e40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mathematics’s Google Aptitude Problem1 Solution by Wolfram and Python language]]></title>
            <link>https://medium.com/@boatchaos179/mathematicss-google-aptitude-problem1-solution-by-wolfram-and-python-language-f61215220980?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/f61215220980</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[wolfram-language]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 07:02:30 GMT</pubDate>
            <atom:updated>2018-10-17T07:02:30.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*3aw6w4RxRpkAJE818314pg.jpeg" /><figcaption><strong>mathematical billboard in Silicon Valley on southbound Highway 101 near Ralston, California in July 2004.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*Mkfw9fsCyhzgf9aW4Fx4rA.jpeg" /></figure><p><strong>note that e is Transcendental Number (In Thai call “จำนวนอดิศัย”)</strong></p><p><strong>A transcendental number is a (possibly complex) number that is not the </strong><a href="http://mathworld.wolfram.com/Root.html"><strong>root</strong></a><strong> of <em>any</em> <em>integer polynomial</em>, meaning that it is not an algebraic number of any degree. Every real transcendental number must also be irrational, since a rational number is, by definition, an algebraic number of degree one.</strong></p><p><strong>in the same meaning is not the root of</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*-e-YAMldoC122Mu1OYB3Bg.jpeg" /></figure><blockquote>with wolfram code</blockquote><p>Wolfram Research CEO and <em>A New Kind of Science</em> author Stephen Wolfram sent the solution as a single line of Mathematica code(Wolfram language) :</p><p>Select[FromDigits/@Partition[First[RealDigits[E,10,1000]],10,1],PrimeQ,1]</p><p>my code check order of answer in Wolfram language :</p><p>PrimeQ[Table[Mod[Floor[10^(n + 10) Exp[1]], 10¹⁰], {n, 0, 100}]]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*OVm0L6vZvsOTf4iIFtRPJg.jpeg" /></figure><p>the answer show that first 10-digit prime in consecutive digits of e is start at 98th digits that exactly answer</p><blockquote>with python code</blockquote><pre><br>import numpy<br>import math<br><br>def prime(a):<br>    if a == 2: return True<br>    if a % 2 == 0: return False<br>    if a &lt; 2: return False<br>    i = 2<br>    n = math.sqrt(a) + 1<br>    while(i &lt; n):<br>        if a % i == 0:<br>            return False<br>        i += 1<br>    return True<br><br>def prime_e():<br>    e = &#39;%0.51f&#39; % math.exp(1)<br>    e = e.replace(&quot;2.&quot;,&quot;&quot;)<br>    for i in range(len(e)):<br>        x = int(e[i:10+i])<br>        if prime(x):<br>            return [i, x]<br><br>print prime_e()</pre><p>output is [20, 5598298427]</p><p>check with wolfram language</p><p>with PrimeQ[5598298427]</p><p>and Table[Mod[Floor[10^(n + 10) Exp[1]], 10¹⁰], {n, 0, 100}]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*ItqozKBRwJhds9a2DNd8oQ.jpeg" /></figure><p>the answer is prime but not precise of real value of e from numerical rounding in coding process can not use this code in range of 100 consecutive digits of e.</p><p>try with Euler’s series expansion python code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*cJVBvyfNrAgplE7jRQ8h4Q.jpeg" /></figure><pre>import operator<br>import decimal as dc<br><br>def edigits(p):<br>    dc.getcontext().prec = p<br>    factorial = 1<br>    euler = 2<br>    for x in range(2, 150):<br>        factorial *= x<br>        euler += dc.Decimal(str(1.0))/dc.Decimal(str(factorial))<br>    return euler<br><br>estring = edigits(150).to_eng_string()[2:]<br><br>for i in range(len(estring)-10):<br>    x = int(reduce(operator.add,estring[i:i+10]))<br>    if isprime(x):<br>        print x<br>        print i<br>        break</pre><p>output is</p><pre>7427466391<br>98</pre><p>in conclude that algorithm and rounding effect with answer the floor function in wolfram language and Euler’s series expansion in python code have precise in range 100 consecutive digits of e.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f61215220980" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to semiring in Computer Science]]></title>
            <link>https://medium.com/@boatchaos179/introduction-semiring-in-computer-science-6dcbab121015?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dcbab121015</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 05 Sep 2018 11:37:20 GMT</pubDate>
            <atom:updated>2018-09-05T13:52:07.864Z</atom:updated>
            <content:encoded><![CDATA[<p>From Nanyang Technological University ( 南洋理工大学) in Singapore lecture</p><p>By Lim Zhi Hao</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S3lgp4KsMlW1ocg8Y5xZmA.jpeg" /></figure><p>semiring in computer science call tuple is a system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*iFE5Xqxge-i1H1HAVrNRIQ.jpeg" /></figure><p>Tropical semiring is a system (ℝ ∪ {+∞},min{x,y},x+y,+∞,0)</p><p>Log semiring is a system (ℝ ∪ {-∞,∞},x(⊕log)y,x+y,+∞,0)</p><p>where x(⊕log)y = -log((e^-x)+(e^-y))</p><p>Boolean semiring is a system ({0,1},x or y,x and y,0,1)</p><p>Proability semiring is a system (ℝ+ ∪ {+∞},x+y,x*y,0,1)</p><p>from Minesutsu lab at University of Tokyo (東京大学)[ 東大] in Japan</p><p>by Josef R. Novak suggest that NLP and ASP application interrest in Tropical semiring and Log semiring</p><blockquote>definition of semiring in Mathematics</blockquote><blockquote>semiring is <strong>ringoid</strong> is system (K, ⊕,⊗)</blockquote><p>with condition for <strong>ringoid</strong></p><p>1.K is a <a href="https://proofwiki.org/wiki/Definition:Set">set</a></p><p>2.⊕ and ⊗ are <strong>binary operation</strong>s on K</p><p>3. the operation ⊗ distributes over ⊕ both right and left.</p><p>∀a,b,c ∈ K : a⊗(b⊕c) = (a⊗b)⊕(a⊗c)…………left distribution</p><p>∀a,b,c ∈ K : (a⊕b)⊗c =(a⊗c)⊕(b⊗c)………….right distribution</p><p>which a⊗(b⊕c) we require that K is closed under ⊕.</p><p>and (a⊗b)⊕(a⊗c) we require that K is closed under ⊗. repectively</p><p>where ∀ b,c ∈ K×K : b⊕c ∈ K</p><p>∀ a,b ∈ K×K : a⊗b ∈ K and ∀ b,c ∈ K×K : b⊗c ∈ K</p><p>4. have Closure property</p><p>other refrence Closure definition <br>(K,*) be an algebraic structure.</p><p>Then K has the property of <strong>closure under </strong>* if and only if</p><p>: ∀x,y ∈ K×K : x*y ∈ K</p><p>K is said to be <strong>closed under *</strong></p><p>or (K,*) is closed</p><p>a system (ℝ,+, ×) is <strong>distributive law </strong>in Algebra</p><p>and</p><blockquote>with 2 condition with <strong>ringoid </strong>condition</blockquote><blockquote>1.(K,⊕) forms a <strong>semigroup</strong></blockquote><blockquote>2.(K,⊕) forms a <strong>semigroup</strong></blockquote><p>A <strong>magma</strong> is an algebraic structure (K,*)such that K is closed under *.</p><p>That is, a <strong>magma</strong> definition</p><p>is a pair (K,*) where:</p><p>K is a set</p><p>* : K×K→K is a binary operation on K</p><blockquote><strong>semigroup</strong> <strong>have 2 axioms</strong> with (K,*)</blockquote><ol><li>from <strong>magma</strong> ∀a,b ∈ K×K : a*b ∈ K (Closure)</li><li>∀a,b,c ∈ K : a*(b*c) = (a*b)*c ( Associativity)</li></ol><blockquote><strong>semiring axioms</strong></blockquote><p>∀a,b ∈ K : a⊕b ∈ K</p><p>∀a,b,c ∈ K : a⊕(b⊕c) = (a⊕b)⊕c</p><p>∀a,b ∈ K : a⊗b ∈ K</p><p>∀a,b,c ∈ K : a⊗(b⊗c) = (a⊗b)⊗c</p><p>∀a,b,c ∈ K : a⊗(b⊕c) = (a⊗b)⊕(a⊗c)…………left distribution</p><p>∀a,b,c ∈ K : (a⊕b)⊗c =(a⊗c)⊕(b⊗c)………….right distribution</p><p>from Signal Processing on Databases Lincoln Laboratory at Massachusetts Institute of Technology in USA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*KeKarFyObnZipa-UfQ9fyA.jpeg" /></figure><p>can be use semiring in product formation in this way</p><p>In computer science it hard to explain with semiring with mathematical way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dcbab121015" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[วิเคราะห์โจทย์ สอวน. (ศูนย์โรงเรียนสวนกุหลาบวิทยาลัย) สาขา คณิตศาสตร์ เรื่อง พหุนามด้วยโปรแกรม R]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B8%A7%E0%B8%B4%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B2%E0%B8%B0%E0%B8%AB%E0%B9%8C%E0%B9%82%E0%B8%88%E0%B8%97%E0%B8%A2%E0%B9%8C-%E0%B8%AA%E0%B8%AD%E0%B8%A7%E0%B8%99-%E0%B8%A8%E0%B8%B9%E0%B8%99%E0%B8%A2%E0%B9%8C%E0%B9%82%E0%B8%A3%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AA%E0%B8%A7%E0%B8%99%E0%B8%81%E0%B8%B8%E0%B8%AB%E0%B8%A5%E0%B8%B2%E0%B8%9A%E0%B8%A7%E0%B8%B4%E0%B8%97%E0%B8%A2%E0%B8%B2%E0%B8%A5%E0%B8%B1%E0%B8%A2-%E0%B8%AA%E0%B8%B2%E0%B8%82%E0%B8%B2-%E0%B8%84%E0%B8%93%E0%B8%B4%E0%B8%95%E0%B8%A8%E0%B8%B2%E0%B8%AA%E0%B8%95%E0%B8%A3%E0%B9%8C-%E0%B9%80%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87-%E0%B8%9E%E0%B8%AB%E0%B8%B8%E0%B8%99%E0%B8%B2%E0%B8%A1%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1-r-e65784cfdcba?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/e65784cfdcba</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 05 Sep 2018 06:53:06 GMT</pubDate>
            <atom:updated>2018-09-05T07:02:51.577Z</atom:updated>
            <content:encoded><![CDATA[<p>Analysis POSN foundation Mathematic Olympiad problem at Suankularb Wittayalai school center in Thailand in Polynomial problem with R programming</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*GBb8OdwACNTHY_IDEonP-w.jpeg" /></figure><p>การวิเคราะห์สมการพหุนามกำลัง 3 นั้นจะพิจารณาได้ยากลำบาก</p><p>ภาควิชาคณิตศาสตร์ Vanderbilt University มหาวิทยาลัยในแนชวิลล์ รัฐเทนเนสซีประเทศ สหรัฐอเมริกา ได้ทำการจัดรูปพหุนามกำลัง3 ไว้ ในหัวข้อเรื่อง “<strong>The Cubic Formula” </strong><a href="https://math.vanderbilt.edu/schectex/courses/cubic/">link</a></p><p>พหุนามกำลัง3 อยู่ในรูป ax³+bx²+cx+d = 0</p><p>ซึ่งค่า x ที่เป็นรากของสมการ จะอยู่ในรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*mfWhSrgIh6k2PXdV1W2Wrw.jpeg" /></figure><p>ซึ่งมีความซับซ้อนกว่า พหุนามกำลัง2 มาก ซึ่งลดความซับซ้อนของตัวแปรโดยการกำหนด ค่าที่อยู่นอกแบบสัมประสิทธิ์ทั่วไปของพหุนามกำลัง3 เพื่อง่ายต่อการวิเคราะห์</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*Oqo3mdSr6N1QutiR_JcOdA.jpeg" /></figure><p>ซึ่งการ ตรวจสอบว่ามีรากของพหุนามกำลัง3 เป็นรากที่เป็นจำนวนจริง จากค่านี้ด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*Up8s9SDJxwCpQA_LAc_VEQ.jpeg" /></figure><p>ต้องมีค่ามากกว่าเท่ากับ 0 ซึ่ง พจน์แรกมีค่ายกกำลัง 2 เป็นค่าบวกเสมอหรือกล่าวเชิงคณิตศาสตร์ คือ มีค่าเป็น 0 หรือ บวกเสมอ</p><p>จึงพิจารณาเฉพาะเพียง กรณีที่ติดลบ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*tD2szUXmNkOvQV11sCecbQ.jpeg" /></figure><p>จากโจทย์ a = 1</p><p>b =-4</p><p>c = 2</p><p>d = -3</p><p>หรือ พิจารณาเฉพาะ ค่า r ก็เพียงพอ มีค่า เท่ากับ (2/(3*(1)))-((-4)²/9*(1)²) = (2/3)-(16/9) = (6–16)/9 = -10/9</p><p>ซึ่งหากค่าเป็นบวกจะสามารถสรุปได้ แต่ค่าออกมาติดลบต้องทำการคำนวณต่อ</p><p>โดยการหาค่า q = pู³ + ((b*c)-(3*a*d))/(6*a²)</p><p>โดยที่ p = -b/(3*a)</p><p>ค่า p = -(-4)/(3*1) = 4/3</p><p>ค่า q = (64/27)+(-8+9)/(6) = (64/27)+(1/6) = 384+27/162 = 441/162</p><p>เห็นได้ชัดเจนว่า q มากกว่า q ชัดเจน จึงมีค่ารากที่เป็นจริงอย่างน้อย 1 ตัวอย่างแน่นอน</p><p><strong>พหุนามกำลัง3 เขียนในรูปแบบทั่วไปได้ยาก ยากต่อการจำ และ การตรวจสอบก็มากพอที่ในสนามแข่งขันจะหมดเวลาในข้อนั้น คือ ทำไม่ทัน</strong></p><p>เมื่อนำมาเขียนด้วยภาษา R เพื่อหาค่าราก x</p><p>โดยกำหนดตัวแปร ตามกำหนดตัวแปรของทางมหาวิทยาลัย Vanderbilt University</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*QUAgOIptXNwGETfi2O4QJg.jpeg" /></figure><p>ได้ผลลัพธ์ คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/1*o8x9I483kS9rBEN3Bq0Hyw.jpeg" /></figure><p>เกิดปัญหากับค่าราก เพราะ เกิดจุดทศนิยม หากออกมาเป็นจำนวนเต็มจะไม่เกิดปัญหาอย่างแน่นอน ต้องทำการตรวจสอบย้อนกลับ(back-test) ด้วยภาษา R</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*8bWTItDQMb0Gc01LROQhdA.jpeg" /></figure><p>เมื่อตรวจสอบรากจำนวนจริงด้วยทศนิยมตำแหน่งที่ 7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/1*jBqoz-qm9pZv_Z9ISvpExQ.jpeg" /></figure><p>ได้ผลลัพธ์ คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/148/1*9gX6o9xsDWPqdFjg3wUfiQ.jpeg" /></figure><p>พบว่าไม่ได้มีค่า = 0</p><p>จึงไม่ใช่รากที่แท้จริง จึงทำการตรวจสอบซ้ำด้วยค่าตัวแปรที่คอมพิวเตอร์ประมวลผล</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/176/1*dsPlfyujvUND7GnL35rJ4w.jpeg" /></figure><p>ได้ผลลัพธ์ คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/183/1*cEpq44StI85_8MY8ekexqA.jpeg" /></figure><p>พบว่าไม่ใช่ค่ารากที่แท้จริง เช่นกัน</p><p>การพิจารณาค่าคลาดเคลื่อน(eror)สามารถทำได้โดยพิจารณาค่าบวกและลบ</p><blockquote>กรณีซึ่งค่ารากจำนวนจริงที่ทศนิยม 6 ตำแหน่ง ได้ ค่าติดลบ</blockquote><p>จากสมการ x³-4x²+2x-3</p><ul><li>-4x²-3 มีค่ามากกว่า x³+2x =x*(x²+2)</li></ul><blockquote>กรณีค่าตัวแปรประมวลผล ได้ค่าบวก</blockquote><p>x³+2x = x*(x²+2) มีค่ามากกว่า -4x²-3</p><p>พิจาณาค่าสัมบูรณ์หรือขนาด จำได้เปรียบเทียบระหว่าง x*(x²+2) และ 4x²+3</p><p>แก้สมการหาค่าจุดเกิดเริ่มเกิดค่าคลาดเคลื่อน x³+2x = 4x²+3 = 0</p><p>x = (4x²+3)/(x²+2)</p><p><strong>เขียนในรูปแบบที่ลดความผิดพลาดของการประมวลของคอมพิวเตอร์</strong></p><p><strong>ได้ log x = log(4x²+3)-log((x²+2))</strong></p><p><strong>เมื่อแก้สมการออกมาจะได้ว่า 0,sqrt(2)i,-sqrt(2)i ,sqrt(3)i/2 และ -sqrt(3)i/2 ตามลำดับ</strong></p><p>แต่ทุกค่าแทนแล้วใช้ไม่ได้ทั้งหมด รากย่อยไม่มีความสัมพันธ์ดับรากจริง</p><p>จึงได้ว่า เป็นจำนวนอตรรกยะ ซึ่งไม่สามารถตรวจสอบได้</p><p>ซึ่งใช้ library base v3.5.1</p><p>จาก <a href="https://www.rdocumentation.org/packages/base">https://www.rdocumentation.org/packages/base</a></p><p>ใน function polyplot()</p><p>ซึ่งนำมาหาค่ารากของสมการพหุนาม ในรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*Cm1kG3sVOfmB8x4-y_Geqw.jpeg" /></figure><p>โดยใช้ Jenkins-Traub algorithm</p><p>ซึ่งมีทั้งสิ้น 3 ขั้นตอน</p><p>ซึ่งมีรูปแบบทั่วไป ในขั้นตอนที่ 3 คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*DuUhJsQ3Xsg7eRU64J2Bxg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*Qj6Q2aLieeFCCFi6Wpxhpg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*jniYniHIlAyq0W7TBfpbiA.jpeg" /></figure><p>ซึ่งจะนำมาเปรียบเทียบกับ Newton–Raphson iteration <a href="https://rpubs.com/aaronsc32/newton-raphson-method">link</a></p><p>โดยใช้ library numDeriv v.2016.8–1</p><p>ซึ่งสร้างฟังก์ชั่นดังนี้ ที่การทำซ้ำ 1000 ครั้ง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*mJhig08RvbfOpZeG7NoiRw.jpeg" /></figure><p>โดยจะมี จุดแตกต่างกับ Jenkins-Traub algorithm ในขั้นตอนที่ 3 คือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*p9saSUh_C4wUNDLpIWYhbQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/1*6tcup2ppbi2aDJiTHMsfAg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*xVr9ZNeqKE23Q41xYFtqaw.jpeg" /></figure><p>ได้ผลลัพธ์ คือ 3.6779934834833985717 ซึ่งหากเขียนในรูปทศนิยมหกตำแหน่งจะได้ 3.677993 ซึ่งตรงกับฟังก์ชั่น cubic ข้างต้น จึงมีความแม่นยำของรากระดับ 1/10⁵</p><p>ทดสอบด้วย tol = 0 ,n = 1,000,000 ในช่วง 3.67793 ถึง 3.6779935</p><p>6x1x5x10 ในช่วงทศนิยม 7 ตำแหน่ง พบว่าเพียง 300 ค่า</p><p>[โดยที่จะหยุดที่ 999,999 ตาม memory ]</p><p>ซึ่งอยู่ในขอบเขตของทศนิยม9ตำแหน่ง ที่เป็นจำนวนอตรรกยะ</p><p>ซึ่งทางผู้เขียนบทความได้ทดสอบแล้ว หากกำหนดช่วงให้ดีๆ จะทำ tol = 0 ได้และจะหยุด</p><p>จึงขอจบการพิจารณาพหุนามกำลัง3เบื้องต้นเพียงเท่านี้</p><p>และตรวจสอบด้วยโปรแกรม R แล้วพบว่าเป็นจำนวนอตรรกยะแน่นอนในช่วงทศนิยม 9 ตำแหน่งซึ่งใกล้เคียงกับสมมติฐานของผู้เขียนบทความ</p><p>หาคำตอบจากโจทยืโดยการกำหนดตัวแปร</p><p>ให้ค่าอัลฟ่า เบต้า แกรมม่า เป็น A,B และ C ตามลำดับเพื่อสะดวกต่อการเข้าใจ</p><p>A,B และ C เป็นรากของสมการ แสดงว่า (x-A)(x-B)(x-C) = 0<strong> ……….(*)</strong></p><p>x³-(A+B+C)x²+(AB+BC+CA)x-ABC =0</p><p>หา <strong>Q(AB) = Q(BC) = Q(CA) = 0 ……….(**)</strong></p><p>ซึ่งจะได้ Q(x)+5 = P(x) ตามโจทย์</p><p>จาก <strong>(**) จะ</strong>ได ้ (x-AB)(x-BC)(x-CA) = 0</p><p>Q(x) = x³-(AB+BC+CA)x²+(A²BC+AB²C+ABC²)x -A²B²C² = 0</p><p>จากโจทย์ x³-4x²+2x-3</p><p>จาก <strong>(*) </strong>จะได้<strong> </strong>A+B+C = 4</p><p>AB+BC+CA = 2</p><p>ABC = 3</p><p>จาก Q(x)</p><p>พบว่ามีปัญหาเพียงพจน์เดียว คือ</p><p>(A²BC+AB²C+ABC²) = ABC(A+B+C) =3*(4) = 12</p><p>แทนค่า Q(x) = x³-2x²+12x-9</p><p><strong>เพราะ ฉะนั้นคำตอบ คือ P(x) = x³-2x²+12x-4</strong></p><p>เมื่อทำการตรวจสอบค่า ABC จาก polyroot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*-C4Q57C8r85Xoz790CNF7w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*xGbxixT67Rbe1FaYt7uFbw.jpeg" /></figure><p>จะได้จัดรูปอย่างง่ายจากโจทย์ (x-3.677935)(x²-0.3220066x+0.8156621)</p><p>ได้ x³ -0.3220066x²+0.8156621x</p><p>-3.677935x²+1.184319x-3</p><p>= x³-3.999942x²+1.999941x-3</p><p><strong>แต่ก็ไม่ใช่ค่าที่ถูกต้องทั้งหมด ซึ่งกระทบต่อสัมประสิทธิ์ตัวอื่นในทศนิยมตำแหน่งที่ 5 และ 3 ก็ไม่ใช่ค่าจริงแต่สามารถอนุโลมได้ จบการวิเคราะห์โครงสร้างพหุนามกำลัง3เบื้องต้นเพียงเท่านี้</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e65784cfdcba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เฉลยข้อสอบคณิตศาสตร์ IJSO (โอลิมปิกวิชาการมัธยมศึกษาตอนต้น) ด้วยโปรแกรม R]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%AA%E0%B8%AD%E0%B8%9A%E0%B8%84%E0%B8%93%E0%B8%B4%E0%B8%95%E0%B8%A8%E0%B8%B2%E0%B8%AA%E0%B8%95%E0%B8%A3%E0%B9%8C-ijso-%E0%B9%82%E0%B8%AD%E0%B8%A5%E0%B8%B4%E0%B8%A1%E0%B8%9B%E0%B8%B4%E0%B8%81%E0%B8%A7%E0%B8%B4%E0%B8%8A%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%A1%E0%B8%B1%E0%B8%98%E0%B8%A2%E0%B8%A1%E0%B8%A8%E0%B8%B6%E0%B8%81%E0%B8%A9%E0%B8%B2%E0%B8%95%E0%B8%AD%E0%B8%99%E0%B8%95%E0%B9%89%E0%B8%99-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1-r-d9c03e1474f?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9c03e1474f</guid>
            <category><![CDATA[education]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 29 Aug 2018 06:32:55 GMT</pubDate>
            <atom:updated>2018-08-29T17:19:51.147Z</atom:updated>
            <content:encoded><![CDATA[<p>Solution for International Junior Science Olympaid (IJSO) with R programming</p><p>เฉลยข้อสอบคณิตศาสตร์ IJSO ครั้งที่ 14 ปี พ.ศ. 2560</p><p>เพื่อคัดเลือกผู้แทนประเทศไทยไปแข่งขัน”วิทยาศาสตร์โอลิมปิกระหว่างประเทศ”</p><p>“International Junior Science Olympaid” (IJSO)14 th 2007</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*K9iQvprtzaD46n3i7JdFew.jpeg" /></figure><p>ขั้นต้นเขียนภาษา R เพื่อเช็คนิยามของค่า ค่าสแควรูทหรือค่าราก( square root) โดยใช้ sqrt() function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/135/1*TfxN_BOdcF75-8gcvTgr5g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*0ROZIZ_H6A2OnUjypeTZlQ.jpeg" /></figure><p>พบว่าตรงกับนิยามทางคณิตศาสตร์ซึ่งในระดับชั้นนี้จะพิจารณาที่มากกว่าเท่ากับ 0 ภายในเครื่องหมายราก</p><p>พิจารณาได้สองกรณี</p><blockquote>3600/(n+18) = 0</blockquote><p>พิจารณาค่า 0 จะ พบว่า ไม่สามารถเป็นจริงได้จึงตัดทิ้ง</p><p>และ</p><blockquote>3600/(n+18) &gt; 0</blockquote><p>พิจารณาค่า 0</p><p>พิจารณาตัวประกอบของ 3600 ด้วย ภาษา R</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*R9MkMTgXtLh8RsTcpmKFfw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*5vBwRfpRndeP2tL1DtHF6g.jpeg" /></figure><p>3600 = (2⁴)(5²)(3²)</p><p>การหารด้วย n+18</p><p>คือ ทำให้ ตัวเศษหายไปและยังยกกำลังเป็นจำนวนคู่เพื่อให้สามรถถอดรากได้</p><p>โดยการใช้การเรียงตัวประกอบ ของ 2²,2⁴,3²และ 5²</p><p>โดยค่าที่สามารถเกิดขึ้น คือ <strong>ผลคูณตัวประกอบที่เป็นไปได้ของ 3600</strong></p><p>1.)2² = 4 คือ 3600/900</p><p>2.)2⁴ = 16 คือ 3600/225</p><p>3.)3² = 9 คือ 3600/400</p><p>4.)5² = 25 คือ 3600/144</p><p>กรณี 2²</p><p>5.) (2²)(3²) = 36 คือ 3600/100</p><p>6.) (2²)(5²) = 100 คือ 3600/36</p><p><strong><em>7.) (2²)(3²)(5²) = 900 คือ 3600/4</em></strong></p><p>กรณี 2⁴</p><p>8.) (2⁴)(3²) =144 คือ 3600/25</p><p><strong><em>9.) (2⁴)(5²) = 400 คือ 3600/9</em></strong></p><p><strong><em>10.) (2⁴)(3²)(5²) = 3600 คือ 3600/1</em></strong></p><p>กรณีพิเศษ</p><p>11.) 1 คือ 3600/3600</p><p><strong><em>12.) (3²)(5²) = 225 คือ 3600/16</em></strong></p><p>เป็นฟังก์ชั่นที่มีผลประทบกับค่า n ไม่โดยตรง</p><p>จึงต้องพิจารณาในรูปแบบ</p><p>x = sqrt(3600/(n+18))</p><p>โดยที่ n มีค่า 1,2,3,4,5,…</p><p>เมื่อนำตัวประกอบของเศษมาหารเพื่อให้ได้ค่าที่สัมพันธ์กับ n+18 จะได้</p><p>x = sqrt(4) เป็นคำตอบต่ำสุดหรือไม่และต้องเช็คเงื่อนไขกับค่า n</p><p>จะได้ x² = 4 = 3600/(n+18)</p><p>ได้ 900 = n+18</p><p>n = 882 เป็นจำนวนเต็มบวกค่านี้สามารถใช้ได้โดยอยู่ภายใต้เงื่อนไขของ n</p><p><strong>เขียนได้ในรูปทั่วไป</strong></p><p><strong>(ผลคูณตัวประกอบที่เป็นไปได้ของ 3600)/3600 = n+18</strong></p><p><strong>จึงตัด ตัวประกอบที่เป็นได้ข้อ7.), 9.) 10.และ 12.) ทิ้ง</strong></p><p>พบว่า 882 ยังไม่ใช่ค่าต่ำสุด จากข้อ 11.) ที่เกิด 3600/3600</p><p>จัดรูปเป็นค่าที่เทียบจำนวนเต็มบวกได้ง่ายๆ x = sqrt(3600/(n+18))</p><p>พิจารณาค่าต่ำสุด โดยที่แทนค่า n = 1</p><p>ได้ 1 = sqrt(3600/(n+18))</p><p>ค่า n สูงสุด = 3600–18 = 3582</p><p>เพราะ ฉะนั้นจะมีทั้งสิ้น 8 ค่า ซึ่งสามารถเช็คได้โดยใช้ภาษา R ตรวจสอบเบื้องต้นใน 1000 ค่าแรก</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*UGLUWyfwPLoiwPTNQ9j5yw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*Pf6y1SBKYvgi96eOkxCirQ.jpeg" /><figcaption>ค่าแรกเริ่มที่ n = 7</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*_F-3Qc9H-R30Bl7z0OoFVw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*Sk7wR3CsJJIXBVdQjj8kSg.jpeg" /><figcaption>ค่าที่ n = 882</figcaption></figure><p>สรุป มีทั้งสิ้น 8 ค่า ตอบ ข้อ A.)</p><p>ควรระวังค่าสุดท้าย เพระ ค่ากระโดดไปไกลมาก หากเขียนโปรแกรมเช็คเบื้องต้นจะหาค่าไม่เจอ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9c03e1474f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เฉลยข้อสอบเมทริกซ์ สอวน.(มูลนิธิส่งเสริมโอลิมปิกวิชาการ) วิชา คอมพิวเตอร์ โดยใช้โปรแกรม R]]></title>
            <link>https://medium.com/@boatchaos179/%E0%B9%80%E0%B8%89%E0%B8%A5%E0%B8%A2%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%AA%E0%B8%AD%E0%B8%9A%E0%B9%80%E0%B8%A1%E0%B8%97%E0%B8%A3%E0%B8%B4%E0%B8%81%E0%B8%8B%E0%B9%8C-%E0%B8%AA%E0%B8%AD%E0%B8%A7%E0%B8%99-%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%99%E0%B8%B4%E0%B8%98%E0%B8%B4%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B9%80%E0%B8%AA%E0%B8%A3%E0%B8%B4%E0%B8%A1%E0%B9%82%E0%B8%AD%E0%B8%A5%E0%B8%B4%E0%B8%A1%E0%B8%9B%E0%B8%B4%E0%B8%84%E0%B8%A7%E0%B8%B4%E0%B8%8A%E0%B8%B2%E0%B8%81%E0%B8%B2%E0%B8%A3-%E0%B8%A7%E0%B8%B4%E0%B8%8A%E0%B8%B2-%E0%B8%84%E0%B8%AD%E0%B8%A1%E0%B8%9E%E0%B8%B4%E0%B8%A7%E0%B9%80%E0%B8%95%E0%B8%AD%E0%B8%A3%E0%B9%8C-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B9%82%E0%B8%9B%E0%B8%A3%E0%B9%81%E0%B8%81%E0%B8%A3%E0%B8%A1-r-eb1504f654?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb1504f654</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[programing]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Wed, 29 Aug 2018 02:58:26 GMT</pubDate>
            <atom:updated>2018-08-29T06:42:29.770Z</atom:updated>
            <content:encoded><![CDATA[<p>Solution for Mathematics Olympaid foundation in Thailand with R programing</p><p>มูลนิธิ สอวน.</p><p>“มูลนิธิส่งเสริมโอลิมปิกวิชาการและพัฒนามาตรฐานวิทยาศาสตร์ศึกษา ในพระอุปถัมภ์สมเด็จพระเจ้าพี่นางเธอเจ้าฟ้ากัลยานิวัฒนา กรมหลวงนราธิวาสราชนครินทร์”</p><p>POSN Foundation</p><p>The Promotion of Academic Olympiads and Development of Science Education Foundation under the Patronage of Her Royal Highness Princess Galyani Vadhana Krom Luang Naradhiwas Rajanagarindra</p><p>ข้อสอบวิชา คอมพิวเตอร์</p><p>เพื่อคัดเลือกนักเรียนเข้าอบรมค่าย 1 สอวน. ปี พ.ศ. 2560(2007)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*V7DfvkaAoOG0PRidJzPkGg.jpeg" /></figure><p>เราไม่สามารถเขียนโปรแกรมนี้ได้ตรงๆเนื่องจาก เก็บค่าว่าง x,y ที่ซ่อนอยู่ในสมาชิกของเมทริกซ์ไม่ได้จึงต้องสร้างสมการออกมาเพื่อสร้างสมการเชิงเส้น ในรูปเมทริกซ์อีกที</p><p>นำมาเรียงใหม่ คือ</p><p>x+y = 2</p><p>5 = x-3</p><p>2y+7 = -5</p><p>x-y = 14</p><p>เมื่อ เรียงใหม่จะได้</p><blockquote>x+y = 2</blockquote><blockquote>x+0y = 8</blockquote><blockquote>0x+2y = -12</blockquote><blockquote>x - y = 14</blockquote><p>จะเห็นได้ชัดเจนว่าถ้านำเมทริกซ์สัมประสิทธิ์มาเขียนจะได้มิติ 4*2</p><p>ในที่นี้ขอเรียกว่า เมทริกซ์ A แต่ เมทริกซ์ตัวแปร ในที่นี้ขอเรียกเมทริกซ์ B มิติ 2*1 จะเกิดปัญหาจึงเขียนเป็นภาษา R ดังนี้ และทำการตรวจสอบด้วยสองวิธีได้ค่าตรงกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*ursualVQG-k1ZmlAH7Pfwg.jpeg" /></figure><p>บรรทัดที่ 1–4 จะไม่สามารถรันผ่าน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*R9vRunJSxCvkasU3Qms3MA.jpeg" /></figure><p>สามารถเขียนเป็นภาษา R ได้ 3 รูปแบบ</p><p>โจทย์ถาม 2x-3y = 2(8)-3(-6) = 34</p><p>ตอบ ข้อ ค.</p><p>หากได้ใช้โปรแกรมเข้ามาช่วยการคำนวณ จะทำให้เข้าใจหลักการในการแก้สมการเชิงเส้นมากขึ้น แต่ในห้องสอบไม่ให้ใช้คอมพิวเตอร์ในรอบนี้</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb1504f654" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The 46th IMO(International Mathematical Olympaid) problem use R to explain host by Mérida Mexico]]></title>
            <link>https://medium.com/@boatchaos179/the-46th-imo-international-mathematical-olympaid-problem-use-r-to-explain-host-by-m%C3%A9rida-mexico-743d4a3c8ac4?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/743d4a3c8ac4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 18:52:29 GMT</pubDate>
            <atom:updated>2018-08-29T17:20:50.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*_4JPuGorf0FRKpivB3LRlg.jpeg" /></figure><p>โจทย์กำหนดให้พิจารณาในขอบเขตจำนวนเต็มบวกทั้งหมด(คือ ค่า n ในโจทย์)ค่าใดเป็นจำนวนเฉพาะสัมพัทธ์กับ a พจน์ที่ n ทุกพจน์(โจทย์ได้รับคำแนะนำจาก ประเทศโปแลนด์)</p><p>จำนวนเฉพาะ(p:prime number) จะเป็นจำนวนเต็มบวกที่มีตัวประกอบสองตัว คือ 1 และ ตัวเอง(p)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*XzdWxAOt-h9yGf2wyx3z_A.jpeg" /><figcaption>จำนวนเฉพาะ 100 ตัวแรก</figcaption></figure><p>เห็นได้ชัดเจนว่าจำนวนเฉพาะเป็นสับเซตของจำนวนเต็มบวก</p><p>จากทฤษฏีบทเล็กของแฟร์มา(Fermat’s little theorem) จะได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*E4tuOvNupnvrYC_mDRIC5g.jpeg" /></figure><p>โดยที่โดย p มากกว่าหรือเท่ากับ 5 , (2,p) = 1, (3,p) = 1, (6,p) = 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*jAxSErjXGCNHFGj3fF-YjA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*NekOiz6nPlN7pZdYh1EI_Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*YPq7ppmAo23xYculVvxQFw.jpeg" /><figcaption>จะได้รูปแบบทั่วไปที่คล้ายกับโจทย์</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*NzFDzz093-e48U1JP1--CQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*IpYNE__aBEZdb7cITlEp5Q.jpeg" /></figure><p>a1 = 10 ,a2 = 48</p><p>โจทย์ถาม (n,aพจน์ที่ n)</p><p>(n,aพจน์ที่ 2 ) &gt; 1</p><blockquote>กรณี n ไม่ใช่จำนวนเฉพาะ</blockquote><p><strong>มี x= 2 หรือ x= 3 เป็นตัวประกอบของ n โดยการตีความโดยผู้เขียนจากสัญลักษณ์ของ Lao ye (ผู้ที่ได้เหรียญทอง)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/108/1*BOe3tuOG-rikVpvpuu-oWw.jpeg" /><figcaption>หากเขียนให้อยู่ในรูปแบบของคณิตศาสตร์</figcaption></figure><blockquote>ส่วนกรณีจำนวนเฉพาะ(p)</blockquote><p>ที่ p มากกว่าหรือ เท่ากับ 5 (n,a พจน์ที่ p-1) &gt; 1 แน่นอน เพราะ ด้วยเงื่อนไข mod a พจน์ที่ p-1 ได้ค่าเท่ากับ 0 และ เมื่อถึงจำนวนเฉพาะ p เมื่อทำการหารร่วมมากแล้วจะได้ค่า p อย่างแน่นอน</p><p>สรุป ตอบมีเพียง 1 ค่า คือ เลข 1 ค่าเดียวที่ตรงกับเงื่อนไขเกิดจำนวนเฉพาะสัมพัทธ์กับลำดับ a พจน์ที่ n ทุกพจน์</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=743d4a3c8ac4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Matrix Operation Mathematical explain with R and Wolfram Programming language]]></title>
            <link>https://medium.com/@boatchaos179/matrix-operation-mathematical-explain-with-r-and-wolfram-programming-language-93b20a65ae80?source=rss-5d9d9bb4ad49------2</link>
            <guid isPermaLink="false">https://medium.com/p/93b20a65ae80</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[education]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nattawat Piansakul]]></dc:creator>
            <pubDate>Tue, 28 Aug 2018 09:34:29 GMT</pubDate>
            <atom:updated>2018-08-28T09:34:29.688Z</atom:updated>
            <content:encoded><![CDATA[<p>In Wolfram language use to better explain how to relate between programming language and mathematical language</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*DCmmR0YGz4_Hj5aiW7513w.jpeg" /><figcaption>construction syntax matrix for wolfram language</figcaption></figure><p>can be wirte in mathematical symbol as det(A) = |A|</p><p>Det[{{a,b},{c,d}}] = -bc+ad</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*6Dz8Lop5xXOVuLt1grJrOg.png" /><figcaption>determinate = area of the parallelogram constructed from the vectors in 2*2 dimension</figcaption></figure><p>Det[{{a,b,c},{d,e,f},{g,h,i}}] = -ceg+bfg+cdh-afh-bdi+aei</p><p>can use Minor for more determinant in dimension 2*2 and use Cofacter method to simplify the higher dimension determinant</p><p>Det[{{a,b,c},{d,e,f},{g,h,i}}] = aDet[{{e,f},{h,i}}]-bDet[{{d,f},{g,i}}]+cDet[{{d,e},{g,h}}]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*RtMKyyljbcc4_Fo4n0zxRQ.png" /><figcaption>determinate = volume of the parallelogram constructed from the vectors in 3*3 dimension (quadruple product)</figcaption></figure><p>in general form of determinant</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/94/1*nW4u-iSbkZf6l5HC2HzCMQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/98/1*8ZLgl5Fp7L4Yr0ePtoTSGw.gif" /></figure><p>with C is Cofactor</p><p>adjugate of <strong>A</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/115/1*Sn0MQSg9u_eGVY4sKqQYug.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*iloEU-2NFrkX9rRGPEqDlw.jpeg" /></figure><p>can be write in generalform<strong> A</strong>adj(<strong>A</strong>) = det(<strong>A</strong>)<strong>I</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*UIbzcbTgZZt6UCPSNN9jiA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*dtPoGlePvaeqlMjZkbRx1A.jpeg" /></figure><p>from Peter J. Kostelec from mathematical department <a href="https://math.dartmouth.edu/archive/m8s00/public_html/handouts/matrices2/node4.html">link</a></p><p>say that <strong>matrix can call divide</strong> but in R and wolfram language and <strong>Mathematics language not have real divide operation</strong></p><p>compare between R and wolfram language with matrix multiplication be tween matrix A and matrix B as matrix C</p><h3>Multiplication</h3><p>in R use</p><blockquote>A%*%B or A %*% B</blockquote><p>in Wolfram</p><blockquote>A.B</blockquote><p>with Mathematical formula <strong>C</strong> = <strong>AB </strong>in<strong> </strong>general form<strong> </strong>mathematical explain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*Y4wIeiUzcFBEf1oS6ln6Rg.jpeg" /><figcaption>note that corresponding dimension k</figcaption></figure><p>beware of operation when multiple</p><p>in R and Wolfram if use this command</p><blockquote>A*B</blockquote><p>with mathematical formula <strong>A</strong> o <strong>B </strong>or othername “<strong>Hadamard product”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*iJfPmZTDyG3b3ppP6ZA6ww.jpeg" /><figcaption>general form of Hadamard product</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*LnxuzCXMHeXCw_WGEkyqyw.jpeg" /><figcaption>in Wolfram more clearly explain with this operation</figcaption></figure><p>the operation / in R and wolfram is the same</p><blockquote>A/B</blockquote><p>has not the mathematical symbol but behavior look like Hadamard product reverse process</p><p>other operation command</p><h3>Determinent</h3><p>In R</p><blockquote>det(A)</blockquote><p>In wolfram</p><blockquote>Det[A]</blockquote><h3>Inverse matrix</h3><p>In R</p><blockquote>solve(A)</blockquote><p>In wolfram</p><blockquote>Inverse[A]</blockquote><p>In R not have built-in function of Minor and Cofactor and adjugate will discuss in other topic later to analysis this later it because have built-in inverse function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93b20a65ae80" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>