<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6352798839577548669</id><updated>2026-07-15T03:27:17.319+08:00</updated><category term="Teaching"/><category term="Mathematica 教學"/><category term="Mathematica 教學 畫圖"/><category term="Mathematica 教學 程式"/><category term="3Q"/><category term="Excel"/><category term="SPSS"/><category term="LaTeX"/><category term="君達呀"/><category term="Kaohsiung"/><category term="Lumia 950"/><category term="Mac"/><category term="Lumia1020"/><category term="Mathematica 教學 微積分"/><category term="Mathematica教學講義"/><category term="愛犬阿寶"/><category term="統計學講義"/><category term="論文免擔心"/><category term="Mathematica"/><category term="JASP教學"/><category term="Mathematica 教學講義"/><category term="中介變數"/><category term="Deterministic cake eating problem"/><category term="Dynamic programming"/><category term="Julia"/><category term="教學講義"/><category term="數值運算"/><category term="CFA"/><category term="Polic function iterations"/><category term="SEM"/><category term="Value function iterations"/><category term="動態幾何繪圖"/><category term="動態操作介面"/><category term="圖表可視化"/><category term="數量方法"/><category term="科學運算"/><category term="符號運算"/><title type='text'>養花種魚數月亮賞星星</title><subtitle type='html'>工作會讓人喪失靈魂。所以寂寞的人總是特別多，看來看去總是這些熟面孔。&#xa;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>461</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-1041038613650707061</id><published>2029-07-22T14:43:00.005+08:00</published><updated>2022-06-11T19:53:04.372+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JASP教學"/><category scheme="http://www.blogger.com/atom/ns#" term="LaTeX"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學講義"/><category scheme="http://www.blogger.com/atom/ns#" term="Teaching"/><title type='text'>這是留言板-既然來了，就留個言再走吧！</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgnQvtzV6NIumqERS60hshHJhMCEoizWDtbV36lKGfrj2AMBO_rBuwSF4U7bhjGa9z8aFIY-SNnA-1kpKPNc-BgKa1SAwfdMP29C-GDDN6-25U6LIaDXbOb36gH1frp2aK3Z3jb66xvBV406WwERrG51Gwq64VVjFmkVXIkD_0mCxPaASHMAfjpESUs=w400-h225&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;640&quot; data-original-width=&quot;960&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgnQvtzV6NIumqERS60hshHJhMCEoizWDtbV36lKGfrj2AMBO_rBuwSF4U7bhjGa9z8aFIY-SNnA-1kpKPNc-BgKa1SAwfdMP29C-GDDN6-25U6LIaDXbOb36gH1frp2aK3Z3jb66xvBV406WwERrG51Gwq64VVjFmkVXIkD_0mCxPaASHMAfjpESUs=w400-h225&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; &lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Please tell me what you thought about this blog. &lt;u&gt;Comments, suggestions and views&lt;/u&gt; are welcomed. &lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/1041038613650707061/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2009/07/blog-post_21.html#comment-form' title='66 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1041038613650707061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1041038613650707061'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2009/07/blog-post_21.html' title='這是留言板-既然來了，就留個言再走吧！'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgnQvtzV6NIumqERS60hshHJhMCEoizWDtbV36lKGfrj2AMBO_rBuwSF4U7bhjGa9z8aFIY-SNnA-1kpKPNc-BgKa1SAwfdMP29C-GDDN6-25U6LIaDXbOb36gH1frp2aK3Z3jb66xvBV406WwERrG51Gwq64VVjFmkVXIkD_0mCxPaASHMAfjpESUs=s72-w400-h225-c" height="72" width="72"/><thr:total>66</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-3451808161645347719</id><published>2025-08-06T07:41:00.009+08:00</published><updated>2025-08-10T21:46:38.845+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學講義"/><title type='text'>Mathematica教學：Simplex method in tableau form</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;240&quot; data-original-width=&quot;754&quot; height=&quot;127&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBWAx_HsGaMYJhmixgUE8qS-5M4ZiRVJqKPPOpiTbA8LQDidV6R5-tHRS_H11CFqz1SX-HQ3giWMYobaMwGtfc2mMWixiZhxEb2qhD7Alf5LouRATzBqm7mroJ3x6_P4NLW-o2Q7zUZt3d3QQHPcmmdEFmAqOyTp1y0sTTf1XpwVL0cNi6VlAsbw-1fbc/w400-h127/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2025_8_6_%E6%B8%85%E6%99%A87_37.png&quot; width=&quot;400&quot; /&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
myConstrains[constrains_] := 
 Block[{num, s, mycon}, num = Length[constrains];
  mycon = 
   Table[If[Head[constrains[[i]]] === LessEqual, 
     constrains[[i]][[1]] + s[i] == constrains[[i]][[2]], 
     If[Head[constrains[[i]]] === Equal, 
      constrains[[i]][[1]] + R[i] == constrains[[i]][[2]], 
      constrains[[i]][[1]] - s[i] + R[i] == 
       constrains[[i]][[2]]]], {i, num}];
  mycon /. x__[y_] :&gt; ToExpression[ToString[x] &lt;&gt; ToString[y]]]

LPstd[obj_, mycons_] := 
 Block[{myvar, basicvars, nonbasicvars, AB, BM, c, A, B, rowindex1, 
   rowindex2}, myvar = Variables[mycons[[All, 1]]];
  myvar = 
   Flatten[{Sort@
      Select[myvar, Not@StringStartsQ[SymbolName[#], &quot;s&quot; | &quot;R&quot;] &amp;], 
     Sort@Select[myvar, StringStartsQ[SymbolName[#], &quot;s&quot;] &amp;], 
     Sort@Select[myvar, StringStartsQ[SymbolName[#], &quot;R&quot;] &amp;]}];
  AB = {Coefficient[mycons[[All, 1]], #] &amp; /@ 
     Select[myvar, Not@StringStartsQ[SymbolName[#], &quot;s&quot; | &quot;R&quot;] &amp;], 
    Coefficient[mycons[[All, 1]], #] &amp; /@ 
     Select[myvar, StringStartsQ[SymbolName[#], &quot;s&quot;] &amp;], 
    Coefficient[mycons[[All, 1]], #] &amp; /@ 
     Select[myvar, StringStartsQ[SymbolName[#], &quot;R&quot;] &amp;]};
  AB = Transpose@Flatten[AB, 1];
  AB = Join[{Flatten[
      Table[Select[myvar, 
        StringStartsQ[SymbolName[#], i] &amp;], {i, {&quot;x&quot;, &quot;s&quot;, &quot;R&quot;}}]]}, 
    AB];
  c = Flatten[{Table[
      Coefficient[obj, #] &amp; /@ 
       Select[myvar, StringStartsQ[SymbolName[#], i] &amp;], {i, {&quot;x&quot;, 
        &quot;s&quot;}}], Table[-BM, {Length[
        Select[myvar, StringStartsQ[SymbolName[#], &quot;R&quot;] &amp;]]}], 0}];
  basicvars = 
   Select[AB[[All, #]] &amp; /@ (Flatten /@ 
        Map[Position[myvar, #] &amp;, 
         Tuples[myvar, {Length[mycons]}], {2}]), #[[2 ;; -1]] === 
       IdentityMatrix[Length[mycons]] &amp;][[1, 1]];
  nonbasicvars = 
   Flatten[Table[
     Select[Complement[myvar, basicvars], 
      StringStartsQ[SymbolName[#], i] &amp;], {i, {&quot;x&quot;, &quot;s&quot;, &quot;R&quot;}}]];
  c = Flatten@{c[[Flatten[Position[myvar, #] &amp; /@ nonbasicvars]]], 
     c[[Flatten[Position[myvar, #] &amp; /@ basicvars]]], 0};
  AB = Join[{Flatten@{nonbasicvars, basicvars}}, 
    Flatten /@ 
     Transpose@{AB[[2 ;; -1]][[All, 
         Sort[Flatten[Position[myvar, #] &amp; /@ nonbasicvars]]]], 
       IdentityMatrix[Length[mycons]]}];
  rowindex1 = c[[-Length[basicvars] - 1 ;; -2]];
  rowindex2 = Range[Length[mycons]];
  Flatten[{c - 
       Total[rowindex1[[#]]*
           Flatten[{AB[[2 ;; -1]][[rowindex2[[#]]]], 
             mycons[[rowindex2[[#]], 2]]}] &amp; /@ 
         Range[Length@rowindex1]], 
      AB[[2 ;; -1]][[All, 
        Sort[Flatten[Position[myvar, #] &amp; /@ nonbasicvars]]]], 
      IdentityMatrix[Length[mycons]], mycons[[All, 2]], 
      Flatten@{Sort@
         Select[nonbasicvars, StringStartsQ[SymbolName[#], &quot;x&quot;] &amp;], 
        Sort@Select[nonbasicvars, 
          StringStartsQ[SymbolName[#], &quot;s&quot;] &amp;], 
        Sort@Select[nonbasicvars, 
          StringStartsQ[SymbolName[#], &quot;R&quot;] &amp;]}, basicvars} &amp; /@ 
    Range[2], 1]]

simplexmethod[c_, A_, B_, b_, xnb_, xb_, cp_, Ap_, Bp_, bp_, xnbp_, 
  xbp_] := 
 Block[{cB, nA, nB, mysymbol, pivotCol, AB, leaveVarpos, Bnew, xbnew, 
   xnbnew, Anew, cnew, znew, z, BM, ABp},
   (*初始化變數*)
   nA = Length[xnb];
   nB = Length[xb];
   
  (*建立符號變數*)
  mysymbol = Flatten@{xnbp, xbp};

  (*找出進入變數（最負的檢驗數）*)
  pivotCol = PositionSmallest[-c[[1 ;; -2]] /. BM -&gt; 10^6][[1]];
  
  (*合併A和B矩陣*)
  AB = Flatten /@ Transpose[{A, B}];
  Print@MatrixForm@AB;
  ABp = Flatten /@ Transpose[{Ap, Bp}];
  leaveVarpos = 
   PositionSmallest[
     b/(If[# &lt;= 0, 10^-6, #] &amp; /@ AB[[All, pivotCol]] /. BM -&gt; 10^6) /. 
      x_ /; x &lt;= 0 -&gt; 10^6][[1]];
  
  (*更新基變數和非基變數*)
  xbnew = xb /. xb[[leaveVarpos]] -&gt; mysymbol[[pivotCol]];
  xnbnew = xnb /. mysymbol[[pivotCol]] -&gt; xb[[leaveVarpos]];
  Bnew = 
   ABp[[All, Flatten[Position[mysymbol, #] &amp; /@ Flatten@{xbnew}]]];
  cB = cp[[Flatten[Position[mysymbol, #] &amp; /@ xbnew]]];
  
  (*計算新的檢驗數和目標函數值*)
  znew = Flatten[{cB . Inverse[Bnew] . Ap - cp[[1 ;; nA]], 
      cB . Inverse[Bnew], cB . Inverse[Bnew] . bp - cp[[-1]]}] // 
    FullSimplify;
  
  (*顯示單形法表格*)
  Print[Grid[
    Insert[Flatten /@ 
      Transpose[{Flatten[{z, xbnew}], 
        Insert[Map[Flatten, 
          Transpose[{Inverse[Bnew] . Ap, Inverse[Bnew], 
            Inverse[Bnew] . bp}]], znew, 1]}], 
     Flatten[{Item[&quot;BasicVariable&quot;, 
        Background -&gt; Lighter[Yellow, 0.9]], mysymbol, &quot;Solution&quot;}], 
     1], Frame -&gt; All, 
    Background -&gt; {{Lighter[Gray, 0.8]}, {Lighter[Yellow, 0.9], 
       Lighter[Pink, 0.9]}}, ItemStyle -&gt; Directive[FontSize -&gt; 16], 
    Spacings -&gt; {Table[5, {Length[mysymbol] + 3}], 2}]];
  
  (*返回更新後的參數*)
  {-Flatten@{cB . Inverse[Bnew] . Ap - cp[[1 ;; nA]], 
       cB . Inverse[Bnew]}, Inverse[Bnew] . Ap, Inverse[Bnew], 
    Inverse[Bnew] . bp, xnbnew, xbnew, cp, Ap, Bp, bp, xnbp, xbp} // 
   FullSimplify]
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
Nest[simplexmethod @@ # &amp;, 
 LPstd[-15 x1 - 20 x2, 
  myConstrains[{x1 + 2 x2 &gt;= 10, 2 x1 - 3 x2 &lt;= 6, x1 + x2 &gt;= 6}]], 2]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/3451808161645347719/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2025/08/mathematicasimplex-method-in-tableau.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/3451808161645347719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/3451808161645347719'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2025/08/mathematicasimplex-method-in-tableau.html' title='Mathematica教學：Simplex method in tableau form'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBWAx_HsGaMYJhmixgUE8qS-5M4ZiRVJqKPPOpiTbA8LQDidV6R5-tHRS_H11CFqz1SX-HQ3giWMYobaMwGtfc2mMWixiZhxEb2qhD7Alf5LouRATzBqm7mroJ3x6_P4NLW-o2Q7zUZt3d3QQHPcmmdEFmAqOyTp1y0sTTf1XpwVL0cNi6VlAsbw-1fbc/s72-w400-h127-c/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2025_8_6_%E6%B8%85%E6%99%A87_37.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-7082977403890115031</id><published>2025-07-31T12:30:00.004+08:00</published><updated>2025-07-31T12:42:39.152+08:00</updated><title type='text'>Mathematica教學：Solving the Traveling Salesman Problem using Gurobi solver</title><content type='html'>&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyBBGSI_2ipyh35Cz1x3Maaji6_1Wp-1v3E_VHQxU0lLyQ1u53eWlgEwTRtLFtdc2h-tfunA1fcVt96v8nmstEFDnQ1dq2rtC9QFYK0RIzopz6lnXv5RZFa3eIpzC1m6Ykm48uR6_mQCBZHqtz4vaArxr3O6M-xrExsn3kyOQGTHQ-D-VnPAYmNBo5AuI/s360/gurobi_tsp.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;359&quot; data-original-width=&quot;360&quot; height=&quot;399&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyBBGSI_2ipyh35Cz1x3Maaji6_1Wp-1v3E_VHQxU0lLyQ1u53eWlgEwTRtLFtdc2h-tfunA1fcVt96v8nmstEFDnQ1dq2rtC9QFYK0RIzopz6lnXv5RZFa3eIpzC1m6Ykm48uR6_mQCBZHqtz4vaArxr3O6M-xrExsn3kyOQGTHQ-D-VnPAYmNBo5AuI/w400-h399/gurobi_tsp.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; 

&lt;p&gt;
  You can download &lt;code&gt;Gurobi solver&lt;/code&gt; from 
  &lt;a href=&quot;https://www.gurobi.com/academia/academic-program-and-licenses/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;
    https://www.gurobi.com/academia/academic-program-and-licenses/
  &lt;/a&gt;.
&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;(* Step 1: Register for an academic license on the Gurobi website and install the Gurobi engine. *)

(* Step 2: Append the Gurobi license path if needed *)
AppendTo[$Path, &quot;your full path to the gurobi.lic directory&quot;]

(* Step 3: Restart Mathematica before continuing *)

(* Generate test data: random 2D points *)
{pts, dist, n} = {#, DistanceMatrix[#], Length[#]} &amp;amp;@RandomReal[{0, 100}, {40, 2}];

(* Define decision variables *)
{xVars, uVars} = {
  Flatten@Table[x[i, j], {i, n}, {j, n}] // DeleteCases[x[i_, i_]],
  Table[u[i], {i, 2, n}]
};

(* Objective function: minimize total distance *)
obj = Total[Flatten[Table[x[i, j], {i, n}, {j, n}]*dist]];

(* Flow constraints: each city must be entered and exited exactly once *)
flow = Flatten@{
  Table[Sum[If[i != j, x[i, j], 0], {j, n}] == 1, {i, n}],
  Table[Sum[If[i != j, x[j, i], 0], {j, n}] == 1, {i, n}]
};

(* Miller-Tucker-Zemlin (MTZ) subtour elimination constraints *)
MTZ=Flatten[Table[If[i!=j&amp;amp;&amp;amp;i&amp;gt;1&amp;amp;&amp;amp;j&amp;gt;1,u[i]-u[j]+n*x[i,j]&amp;lt;=n-1,
Nothing],{i,n},{j,n}]];

(* Variable domains and integrality conditions *)
vardomain=Flatten@{
Thread[0&amp;lt;=xVars&amp;lt;=1],
u[1]==1,Thread[2&amp;lt;=uVars&amp;lt;=n],
xVars∈Integers,uVars∈Integers};

(* Solve the model using Gurobi *)
{optDist,sol}=NMinimize[
Flatten@{obj,flow,MTZ,vardomain},
Join[xVars,uVars],
Method-&amp;gt;&quot;Gurobi&quot;];

(* Extract path from the binary decision variables *)
edges=Cases[sol,(x[i_,j_]-&amp;gt;1):&amp;gt;{i,j}];
path=NestList[
Cases[edges,{#[[2]],_}][[1]]&amp;amp;,
edges[[1]],
Length@edges-1];

(* Visualization of the solution *)
Graphics[{
  {Red, PointSize[Large], Point@pts},
  {Blue, Thick, Line[pts[[#]] &amp;amp; /@ path]},
  {Green, PointSize[.02], Point@pts[[1]]},
  {Arrowheads[.02], Arrow[pts[[#]] &amp;amp; /@ path]}},
 Frame -&amp;gt; True,
 PlotLabel -&amp;gt; Row[{&quot;TSP: n=&quot;, n, &quot;, distance=&quot;, optDist}]
]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/7082977403890115031/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematicasolving-traveling-salesman.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7082977403890115031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7082977403890115031'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematicasolving-traveling-salesman.html' title='Mathematica教學：Solving the Traveling Salesman Problem using Gurobi solver'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyBBGSI_2ipyh35Cz1x3Maaji6_1Wp-1v3E_VHQxU0lLyQ1u53eWlgEwTRtLFtdc2h-tfunA1fcVt96v8nmstEFDnQ1dq2rtC9QFYK0RIzopz6lnXv5RZFa3eIpzC1m6Ykm48uR6_mQCBZHqtz4vaArxr3O6M-xrExsn3kyOQGTHQ-D-VnPAYmNBo5AuI/s72-w400-h399-c/gurobi_tsp.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-8009165854699587088</id><published>2025-07-29T10:01:00.007+08:00</published><updated>2025-07-31T12:31:17.217+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica教學講義"/><category scheme="http://www.blogger.com/atom/ns#" term="Teaching"/><title type='text'>Mathematica 教學：Searoute for Traveling Salesman Problem</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;332&quot; data-original-width=&quot;663&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjdeJLltRt0H-ni4Z5-_JwGnztkSEQkumr0oBdWueixhfP71mlUXSDOD55tnyWDvBLv3m_PkzrsxZyitdw8T5noFY8_XMuOsDXRVQrLxHqKabbD5J4HnMQn6izWENQZuFZ1WFCC1-Nb_qmHq3TVFxhqOM2bGhyVJbcGDcy1C6mezabOpQeRCwCvoY6X5U/w400-h200/Untitled.png&quot; width=&quot;400&quot; /&gt;&lt;/div&gt;&lt;br /&gt;

&lt;p&gt;
  You can download &lt;code&gt;searoute&lt;/code&gt; from 
  &lt;a href=&quot;https://github.com/eurostat/searoute&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;
    https://github.com/eurostat/searoute
  &lt;/a&gt;.
&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;port = {
 {&quot;Shanghai, China&quot;, 31.2304, 121.4737},
 {&quot;Guangzhou, China&quot;, 23.1291, 113.2644},
 {&quot;Rotterdam, Netherlands&quot;, 51.9225, 4.4792},
 {&quot;Antwerp, Belgium&quot;, 51.2194, 4.4025},
 {&quot;Valencia, Spain&quot;, 39.4699, -0.3763},
 {&quot;Los Angeles, USA&quot;, 33.7405, -118.2719},
 {&quot;New York/New Jersey, USA&quot;, 40.6687, -74.0451},
 {&quot;Savannah, USA&quot;, 32.0809, -81.0912},
 {&quot;Santos, Brazil&quot;, -23.9608, -46.3336},
 {&quot;Buenos Aires, Argentina&quot;, -34.6037, -58.3816},
 {&quot;Itajai, Brazil&quot;, -26.9101, -48.6703},
 {&quot;Tangier Med, Morocco&quot;, 35.8844, -5.5036},
 {&quot;Port Said, Egypt&quot;, 31.2653, 32.3019},
 {&quot;Durban, South Africa&quot;, -29.8587, 31.0218},
 {&quot;Melbourne, Australia&quot;, -37.8136, 144.9631},
 {&quot;Auckland, New Zealand&quot;, -36.8485, 174.7633},
 {&quot;Brisbane, Australia&quot;, -27.4698, 153.0251},
 {&quot;Singapore, Singapore&quot;, 1.3521, 103.8198},
 {&quot;Kaohsiung, Taiwan&quot;, 22.6273, 120.3014},
 {&quot;Busan, South Korea&quot;, 35.1796, 129.0756},
 {&quot;Hong Kong, China&quot;, 22.3193, 114.1694},
 {&quot;Tanjung Pelepas, Malaysia&quot;, 1.3673, 103.5386},
 {&quot;Jebel Ali, UAE&quot;, 25.015, 55.0633},
 {&quot;Colombo, Sri Lanka&quot;, 6.9271, 79.8612},
 {&quot;Felixstowe, UK&quot;, 51.9556, 1.3111},
 {&quot;Algeciras, Spain&quot;, 36.1408, -5.4562},
 {&quot;Vancouver, Canada&quot;, 49.2827, -123.1207},
 {&quot;Port Klang, Malaysia&quot;, 3.0089, 101.3678},
 {&quot;Laem Chabang, Thailand&quot;, 13.0846, 100.8956},
 {&quot;Tokyo, Japan&quot;, 35.6828, 139.7595},
 {&quot;Yokohama, Japan&quot;, 35.4437, 139.6380}
};

Export[&quot;/Users/yourname/Desktop/searoute/text.csv&quot;,
Insert[
Flatten@{#[[1,1]]&amp;lt;&amp;gt;&quot; to &quot;&amp;lt;&amp;gt;#[[2,1]],
Round[#[[1,3]],0.1],Round[#[[1,2]],0.1],
Round[#[[2,3]],0.1],Round[#[[2,2]],0.1]}&amp;amp;/@
Select[
Flatten[Table[{port[[i]],port[[j]]},
{i,Length@port},{j,Length@port}],1],
#[[1]]!=#[[2]]&amp;amp;
],
{&quot;routename&quot;,&quot;olon&quot;,&quot;olat&quot;,&quot;dlon&quot;,&quot;dlat&quot;},1]
];

RunProcess[{&quot;java&quot;,&quot;-jar&quot;,
&quot;/Users/yourname/Desktop/searoute/searoute.jar&quot;,
&quot;/Users/yourname/Desktop/searoute/text.csv&quot;,
&quot;-res&quot;,&quot;5&quot;,&quot;-panama&quot;,&quot;1&quot;,&quot;-suez&quot;,&quot;1&quot;}]

route=Import[&quot;/Users/yourname/Desktop/searoute/out.geojson&quot;,
&quot;Data&quot;][[2,2]];

mypath=Flatten@{#[[2,2]],StringSplit[&quot;routename&quot;/.#[[3,2]],&quot; to &quot;],
&quot;distKM&quot;/.#[[3,2]]}&amp;amp;/@route;

myrule=Rule@@@Transpose@{Tally[mypath[[All,2]]][[All,1]],
Range[Length@port]};

distMatrix=ParallelTable[If[i==j,Infinity,
ToExpression@Select[mypath/.myrule,
#[[2]]==i&amp;amp;&amp;amp;#[[3]]==j&amp;amp;][[1,-1]]],
{i,Length@port},{j,Length@port}];

tour=FindShortestTour[Range[Length@port],
DistanceFunction-&amp;gt;(distMatrix[[#1,#2]]&amp;amp;)];

myline=ParallelTable[
If[i==j,{},Select[mypath/.myrule,#[[2]]==i&amp;amp;&amp;amp;#[[3]]==j&amp;amp;][[1,1]]],
{i,Length@port},{j,Length@port}];

myline=myline[[#[[1]],#[[2]]]]&amp;amp;/@Partition[tour[[2]],2,1];

GeoGraphics[{
Red,PointSize[Large],
Point[GeoPosition[port[[All,{2,3}]]]],
Blue,Thick,myline},
GeoRange-&amp;gt;&quot;World&quot;,
GeoCenter-&amp;gt;GeoPosition[{20,-150}],
GeoRange-&amp;gt;Quantity[180,&quot;AngularDegrees&quot;]
]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/8009165854699587088/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematica-searoute-for-traveling.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/8009165854699587088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/8009165854699587088'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematica-searoute-for-traveling.html' title='Mathematica 教學：Searoute for Traveling Salesman Problem'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjdeJLltRt0H-ni4Z5-_JwGnztkSEQkumr0oBdWueixhfP71mlUXSDOD55tnyWDvBLv3m_PkzrsxZyitdw8T5noFY8_XMuOsDXRVQrLxHqKabbD5J4HnMQn6izWENQZuFZ1WFCC1-Nb_qmHq3TVFxhqOM2bGhyVJbcGDcy1C6mezabOpQeRCwCvoY6X5U/s72-w400-h200-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5267071019965058314</id><published>2025-07-16T22:57:00.006+08:00</published><updated>2025-07-19T23:49:37.424+08:00</updated><title type='text'>Mathematica 教學：Tikz Plot for Traveling Salesman Problem</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;435&quot; data-original-width=&quot;451&quot; height=&quot;386&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc5ruQCxQQL4aHNWA5ozauQ1RaaoioXZHkLeOahhUXcrn_FOx_IsoPVFDgb_ZYeUQyxU9GWInxJ2BFvWWbQCvubzymKt1yVE0ldBHdlY3dijCIynPkPTuELbZJ37cnYZh_s63dixOozAjaPM90xEC53tObxQKvL0hJaFvQhNk94APF-nsmz3glpUacsC0/w400-h386/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2025_7_16_%E6%99%9A%E4%B8%8A10_52.png&quot; width=&quot;400&quot; /&gt;&lt;/div&gt; 


&lt;pre class=&quot;prettyprint&quot;&gt;pathtikz[tour_,coords_]:=Block[{nodeStrings,nodeBlock,pathString,startNode},
startNode=tour[[1]];

(*節點資料字串*)
nodeStrings=MapIndexed[StringTemplate[&quot;``/``/``/``,\n&quot;]@@
{tour[[#2[[1]]]],#[[1]],#[[2]],If[#2[[1]]==1,&quot;green&quot;,&quot;red&quot;]}&amp;amp;,coords];

(*把最後一個的逗號拿掉*)
nodeBlock=StringJoin@Riffle[Most[nodeStrings],&quot;&quot;]&amp;lt;&amp;gt;
StringReplace[Last[nodeStrings],&quot;,\n&quot;-&amp;gt;&quot;}&quot;];

(*路徑字串*)
pathString=StringJoin[Riffle[&quot;(&quot;&amp;lt;&amp;gt;ToString[#]&amp;lt;&amp;gt;&quot;)&quot;&amp;amp;/@tour,&quot;--&quot;]];

pathString=pathString&amp;lt;&amp;gt;&quot;--(1);&quot;;

(*組合 TikZ code*)
latexCode=StringTemplate[&quot;
\\begin{minipage}{\\linewidth}
\\centering
\\textbf{圖：最佳TSP巡迴路徑} \\\\[0.5em]
\\fbox{%
\\begin{tikzpicture}[scale=0.08]

% 節點座標與顏色：第1個為綠色，其餘為紅色
\\foreach \\i/\\x/\\y/\\c in {
``
{
  \\node[draw, circle, fill=\\c, inner sep=2pt] (\\i) at (\\x,\\y) {};
  \\node[font=\\tiny] at (\\x + 2, \\y + 2) {\\i};
}

% 最佳路徑
  \\draw[blue, thick]
  ``
  \\end{tikzpicture}
}
\\end{minipage}
&quot;][nodeBlock,pathString]]

test = RandomReal[{0, 100}, {50, 2}];
ans = FindShortestTour[test];

tour = ans[[2]][[1 ;; -2]];
coords = test[[tour]];

pathtikz[tour, coords]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5267071019965058314/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematica-tike-plot-for-traveling.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5267071019965058314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5267071019965058314'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2025/07/mathematica-tike-plot-for-traveling.html' title='Mathematica 教學：Tikz Plot for Traveling Salesman Problem'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgc5ruQCxQQL4aHNWA5ozauQ1RaaoioXZHkLeOahhUXcrn_FOx_IsoPVFDgb_ZYeUQyxU9GWInxJ2BFvWWbQCvubzymKt1yVE0ldBHdlY3dijCIynPkPTuELbZJ37cnYZh_s63dixOozAjaPM90xEC53tObxQKvL0hJaFvQhNk94APF-nsmz3glpUacsC0/s72-w400-h386-c/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2025_7_16_%E6%99%9A%E4%B8%8A10_52.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-7383727632816100027</id><published>2024-11-24T16:26:00.005+08:00</published><updated>2024-11-24T16:33:50.171+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica教學講義"/><category scheme="http://www.blogger.com/atom/ns#" term="教學講義"/><title type='text'>Mathematica 教學：Dijkstra Algorithm </title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;432&quot; data-original-width=&quot;271&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhZfg_BYk60ujrCxKUOM4otOAB48P-zj90-K-RamegTvVszzAYrbrgHH31NFfIPGEdJCFtSZWj6CACcuOc4XBBDlaB2WM6YTwDWDFc_w5kSs7HCas_CrSZQAVnR17cemruc7Qxs5ArNNczQrKqTG0MYgMDb20pmpv_yXXPcQ9ibuqcsuhoxTxu8_OavCD8=w252-h400&quot; width=&quot;252&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Concise and elegant!&lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;g=Graph[
{1\[DirectedEdge]2,1\[DirectedEdge]3,2\[DirectedEdge]3,
2\[DirectedEdge]4,3\[DirectedEdge]5,4\[DirectedEdge]3,
4\[DirectedEdge]5,4\[DirectedEdge]6,5\[DirectedEdge]6},
EdgeWeight-&amp;gt;{1,12,9,3,5,3,13,15,4},
EdgeLabels-&amp;gt;Rule@@@Transpose@{
{1\[DirectedEdge]2,1\[DirectedEdge]3,2\[DirectedEdge]3,
2\[DirectedEdge]4,3\[DirectedEdge]5,4\[DirectedEdge]3,
4\[DirectedEdge]5,4\[DirectedEdge]6,5\[DirectedEdge]6},
{1,12,9,3,5,3,13,15,4}},
VertexStyle-&amp;gt;Yellow,VertexSize-&amp;gt;0.5,
VertexShapeFunction-&amp;gt;{{Yellow,Disk[#1,0.1],Black,Text[#2,#1]}&amp;amp;}]

route={{1,2,1},{1,3,12},{2,3,9},{2,4,3},{3,5,5},{4,3,4},{4,5,13},{5,6,4},{4,6,15}};

myroute=Select[Table[Select[route,#[[2]]==z&amp;amp;],{z,1,6}],#=!={}&amp;amp;]

Table[Set[v[temp], 
SortBy[If[#[[1]]==1,{v[temp],#[[3]]},{v[temp],v[#[[1]]]+#[[3]]}]&amp;amp;/@
Select[Flatten[myroute,1],#[[2]]==temp&amp;amp;],Last][[1,2]]],{temp,2,6}]&amp;amp;/@Range[2]

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/7383727632816100027/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2024/11/mathematica-dijkstra-algorithm.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7383727632816100027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7383727632816100027'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2024/11/mathematica-dijkstra-algorithm.html' title='Mathematica 教學：Dijkstra Algorithm '/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhZfg_BYk60ujrCxKUOM4otOAB48P-zj90-K-RamegTvVszzAYrbrgHH31NFfIPGEdJCFtSZWj6CACcuOc4XBBDlaB2WM6YTwDWDFc_w5kSs7HCas_CrSZQAVnR17cemruc7Qxs5ArNNczQrKqTG0MYgMDb20pmpv_yXXPcQ9ibuqcsuhoxTxu8_OavCD8=s72-w252-h400-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-7775214751798241478</id><published>2024-01-05T15:32:00.015+08:00</published><updated>2024-03-05T09:14:48.067+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Julia"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="數值運算"/><title type='text'>Finally, the first acceptance of 2024 comes.</title><content type='html'>&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQjXlMUSfHMZNV-MWNkXzxYI-X93s7V-Yzjur2_lV-X8-9oE-nohvl6D_k-k8GUCmDTjyz29jbowb3ijqkhyYytgLzLuowuRHt7Tx5znXnWnxfUugvgxTkkXtYKTKn7TNkPFLeHJqHqy7fJtrMW5MNM1l3CamdfO7hlsP7IdGwH0VS-Hvmt82-LhoTllc/s614/Untitled.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;382&quot; data-original-width=&quot;614&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQjXlMUSfHMZNV-MWNkXzxYI-X93s7V-Yzjur2_lV-X8-9oE-nohvl6D_k-k8GUCmDTjyz29jbowb3ijqkhyYytgLzLuowuRHt7Tx5znXnWnxfUugvgxTkkXtYKTKn7TNkPFLeHJqHqy7fJtrMW5MNM1l3CamdfO7hlsP7IdGwH0VS-Hvmt82-LhoTllc/s400/Untitled.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;div style=&quot;text-align: center;&quot;&gt;A Sustainable Dynamic Optimization Model of Pricing and Advertising in the Presence of Green Innovation Investment&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;Chung-Yuan Dye and Tsu-Pang Hsieh&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Finally, the acceptance from EJOR has arrived. The Julia code for the numerical examples in this paper is provided below. Alternatively, you can also implement it directly in Julia. Please leave a message if you have any problems with the implementation of the code.

&lt;pre class=&quot;prettyprint&quot;&gt;julia=StartExternalSession[&quot;Julia&quot;]

ExternalEvaluate[julia,&quot;
using JuMP,Ipopt
dp(x)=(140-3*x);
K1(y)=(y/5-y^2/1000);
f1(x)=100*exp(-0.03*x);
f2(x)=2*exp(-0.045*x);
v1=25;
v2=10;
omega=300;
c=16.5;
h=0;
z=0.8;
&quot;];

dynCP11=ExternalEvaluate[julia, &quot;
	function dynCP11(G0,gamma1,gamma2,delta,k1coef,k2coef,e,r,varpi,n)
    m1 = Model(Ipopt.Optimizer) 
    set_silent(m1)
    #set_optimizer_attributes(m1, \&quot;tol\&quot; =&amp;gt; 1e-4, \&quot;max_iter\&quot; =&amp;gt; 100)
    register(m1, :dp, 1, dp; autodiff = true)
    register(m1, :K1, 1, K1; autodiff = true)
    register(m1, :f1, 1, f1; autodiff = true)
    register(m1, :f2, 1, f2; autodiff = true)
    @variable(m1, p[1:n], start = 30)
    @variable(m1, w[1:n], start = 10)
    @variable(m1, u[1:n], start = 10)

    @NLexpression(m1,newG[i=1:n],(1-delta)^(-1+i)*((1-delta)*G0
	+sum((gamma1*u[j+1]^k1coef+gamma2*w[j+1]^k2coef)/((1-delta)^j) 
    for j = 0:i-1)))
    
    @NLexpression(m1,newCE[i=1:n],f1(w[i])+f2(w[i])*dp(p[i])*K1(newG[i])-varpi)

    @NLobjective(
	m1,
	Max,
	sum(z^(i-1)*((p[i]-c-h/2)*dp(p[i])*K1(newG[i])
    -v1*u[i]^2/2-v2*w[i]^2/2-e*newCE[i])
                for i = 1:n))
	for i = 1:n
        @constraint(m1, p[i] &amp;gt;= c + h / 2)
	end
	for i = 1:n
        @constraint(m1, p[i] &amp;lt;= 140 / 3)
	end
	for i = 1:n
        @constraint(m1, w[i] &amp;gt;= 0)
	end
	for i = 1:n
        @constraint(m1, u[i] &amp;gt;= 0)
	end
	for i = 1:n
        @NLconstraint(m1, newCE[i] &amp;gt;= 0)
	end

	JuMP.optimize!(m1)

	p_val = JuMP.value.(p)
	w_val = JuMP.value.(w)
	u_val = JuMP.value.(u)

	G_val=(1-delta)*G0+gamma1*u_val[1]^k1coef+gamma2*w_val[1]^k2coef

	CE=f1(w_val[1])+f2(w_val[1])*dp(p_val[1])*K1(G_val)

	profit=(p_val[1]-c-h/2)*dp(p_val[1])*K1(G_val)
    -v1*u_val[1]^2/2-v2*w_val[1]^2/2-e*(CE-varpi)

	return[p_val,w_val,u_val,G_val,CE,profit,objective_value(m1)]

end&quot;];

dynCP22=ExternalEvaluate[julia,&quot;
	function dynCP22(G0,gamma1,gamma2,delta,k1coef,k2coef,e,r,varpi,n)
    m1 = Model(Ipopt.Optimizer) 
    set_silent(m1)
    #set_optimizer_attributes(m1, \&quot;tol\&quot; =&amp;gt; 1e-4, \&quot;max_iter\&quot; =&amp;gt; 100)
    register(m1, :dp, 1, dp; autodiff = true)
    register(m1, :K1, 1, K1; autodiff = true)
    register(m1, :f1, 1, f1; autodiff = true)
    register(m1, :f2, 1, f2; autodiff = true)
    @variable(m1, p[1:n], start = 30)
    @variable(m1, w[1:n], start = 10)
    @variable(m1, u[1:n], start = 10)

    @NLexpression(m1,newG[i=1:n],(1-delta)^(-1+i)*((1-delta)*G0
	+sum((gamma1*u[j+1]^k1coef+gamma2*w[j+1]^k2coef)/((1-delta)^j) 
    for j = 0:i-1)))
    
    @NLexpression(m1,newCE[i=1:n],f1(w[i])+f2(w[i])*dp(p[i])*K1(newG[i])-varpi)

    @NLobjective(
	m1,
	Max,
	sum(z^(i-1)*((p[i]-c-h/2)*dp(p[i])*K1(newG[i])
    -v1*u[i]^2/2-v2*w[i]^2/2-r*newCE[i])
                for i = 1:n))
	for i = 1:n
        @constraint(m1, p[i] &amp;gt;= c + h / 2)
	end
	for i = 1:n
        @constraint(m1, p[i] &amp;lt;= 140 / 3)
	end
	for i = 1:n
        @constraint(m1, w[i] &amp;gt;= 0)
	end
	for i = 1:n
        @constraint(m1, u[i] &amp;gt;= 0)
	end
	for i = 1:n
        @NLconstraint(m1, newCE[i] &amp;lt;= 0)
	end

	JuMP.optimize!(m1)

	p_val = JuMP.value.(p)
	w_val = JuMP.value.(w)
	u_val = JuMP.value.(u)

	G_val=(1-delta)*G0+gamma1*u_val[1]^k1coef+gamma2*w_val[1]^k2coef

	CE=f1(w_val[1])+f2(w_val[1])*dp(p_val[1])*K1(G_val)

	profit=(p_val[1]-c-h/2)*dp(p_val[1])*K1(G_val)
    -v1*u_val[1]^2/2-v2*w_val[1]^2/2-r*(CE-varpi)

	return[p_val,w_val,u_val,G_val,CE,profit,objective_value(m1)]

end&quot;];

mysol13[g0_,\[Gamma]1_,\[Gamma]2_,\[Delta]_,k1_,k2_,e_,r_,cap_]:=
Block[{n=40,numiter=100,iter=0,ans1,ans2},
	Print[{Dynamic[iter],Dynamic[ans2]}];
	NestList[(
	iter=iter+1;
	ans1=
	SortBy[{
		dynCP11[#[[4]],\[Gamma]1,\[Gamma]2,\[Delta],k1,k2,e,r,cap,n],
		dynCP22[#[[4]],\[Gamma]1,\[Gamma]2,\[Delta],k1,k2,e,r,cap,n]},
          Last][[-1]];
	ans2={ans1[[1,1]],ans1[[2,1]],ans1[[3,1]],ans1[[4]],
          ans1[[5]],#[[-1]]+0.8^(iter-1)*ans1[[6]]})&amp;amp;,
	{0,0,0,g0,0,0},numiter][[2;;-1]]
]

myexample=mysol13[#[[1]],0.5,0.8,0.2,0.5,0.8,8,2,#[[2]]]&amp;amp;/@
Flatten[Table[{i,j},{j,{250,300,400}},{i,{10,40}}],1]

ListLinePlot[myexample[[All,All,#]],PlotRange-&amp;gt;All,
Frame-&amp;gt;True]&amp;amp;/@{1,2,3,4,5}//Column
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/7775214751798241478/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2024/01/finally-first-acceptance-of-2024-comes.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7775214751798241478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7775214751798241478'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2024/01/finally-first-acceptance-of-2024-comes.html' title='Finally, the first acceptance of 2024 comes.'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQjXlMUSfHMZNV-MWNkXzxYI-X93s7V-Yzjur2_lV-X8-9oE-nohvl6D_k-k8GUCmDTjyz29jbowb3ijqkhyYytgLzLuowuRHt7Tx5znXnWnxfUugvgxTkkXtYKTKn7TNkPFLeHJqHqy7fJtrMW5MNM1l3CamdfO7hlsP7IdGwH0VS-Hvmt82-LhoTllc/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-4414002966046268423</id><published>2023-12-25T23:28:00.001+08:00</published><updated>2023-12-25T23:28:40.353+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><title type='text'>Mathematica 教學：Text arrangement</title><content type='html'>&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRlEyqXC_q6Z5ap5g7laC0JT7fvPciSHiRdSIibSjsLe1HuVp8Tk7Fh0iESUkGo2z0JYRfjbaxotqXbGYRKlUBB-FxljY0qmfllX8syzPgUry5e7N-aWkGL-v5yuuWX2c8By99OX6nfTJ_5u_cTnAZExsCn1YBH3nY8Y1VbRSwBCRezYVoLDO7iYtU9PA/s1600/Untitled.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;1413&quot; data-original-width=&quot;1308&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRlEyqXC_q6Z5ap5g7laC0JT7fvPciSHiRdSIibSjsLe1HuVp8Tk7Fh0iESUkGo2z0JYRfjbaxotqXbGYRKlUBB-FxljY0qmfllX8syzPgUry5e7N-aWkGL-v5yuuWX2c8By99OX6nfTJ_5u_cTnAZExsCn1YBH3nY8Y1VbRSwBCRezYVoLDO7iYtU9PA/w370-h400/Untitled.png&quot; width=&quot;370&quot; /&gt;&lt;/a&gt;


&lt;pre class=&quot;prettyprint&quot;&gt;test=ImageData[Rasterize[&quot;50&quot;,RasterSize-&amp;gt;50,ImageSize-&amp;gt;200]]

data=ParallelTable[{i,j,If[Mean@test[[i,j]]&amp;gt;0.95,0,1]},
{i,Dimensions[test][[1]]},{j,Dimensions[test][[2]]}]

picdata=Table[ParallelMap[If[#[[-1]]==0,&quot;&quot;,
ImageResize[Import[RandomChoice[FileNames[&quot;*.jpeg&quot;,
&quot;/Users/chungyuandye/Pictures/照片圖庫V4.photoslibrary/originals/&quot;,Infinity]]],{100,100}]]&amp;amp;,
data[[i]]],{i,54}]

GraphicsGrid[picdata]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/4414002966046268423/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2023/12/mathematica-text-arrangement.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/4414002966046268423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/4414002966046268423'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2023/12/mathematica-text-arrangement.html' title='Mathematica 教學：Text arrangement'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRlEyqXC_q6Z5ap5g7laC0JT7fvPciSHiRdSIibSjsLe1HuVp8Tk7Fh0iESUkGo2z0JYRfjbaxotqXbGYRKlUBB-FxljY0qmfllX8syzPgUry5e7N-aWkGL-v5yuuWX2c8By99OX6nfTJ_5u_cTnAZExsCn1YBH3nY8Y1VbRSwBCRezYVoLDO7iYtU9PA/s72-w370-h400-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-910084171626943391</id><published>2023-04-07T11:45:00.005+08:00</published><updated>2023-04-07T11:54:50.678+08:00</updated><title type='text'>Tikz: Drawing Random Circles with Randomly Assigned Centers and Radii</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;436&quot; data-original-width=&quot;422&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgpWXykmsKLB_zJsUhNqKM9tZqpORKex4FV5Ecs4fyktp5bKKekp2DhIZjttFEViyvJgzj9c_nSliZZ7OV0ggBaH3sIpwp1A7jx8lzWq4h2z7MS_2ASTGpm-2Hc9B4FysWhSvOKwKeVL_rAk4qsvqJJmPzkJkL0R8DeBO-WIzbrf6B5xwoapnwSnObr=w387-h400&quot; width=&quot;387&quot; /&gt;&lt;/div&gt;&lt;pre class=&quot;prettyprint&quot;&gt;
\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}
\begin{document}
\begin{center}
\begin{adjustbox}{width=0.6\textwidth}
  \begin{tikzpicture}
  \pgfmathsetseed{42}
    \foreach \i in {1,...,500}
    {
      \pgfmathsetmacro{\a}{int(random(0,255))}
      \pgfmathsetmacro{\b}{int(random(0,255))}
      \pgfmathsetmacro{\c}{int(random(0,255))}
      \pgfmathsetmacro{\r}{rand*2}
      \pgfmathsetmacro{\x}{random(-10,10)}
      \pgfmathsetmacro{\y}{random(-10,10)}
      \definecolor{mycolor}{RGB}{\a,\b,\c}
      \fill[mycolor] (\x,\y) circle (\r cm);
    }
  \end{tikzpicture}
  \end{adjustbox}
  \end{center}
\end{document}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/910084171626943391/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2023/04/tikz-drawing-random-circles-with.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/910084171626943391'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/910084171626943391'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2023/04/tikz-drawing-random-circles-with.html' title='Tikz: Drawing Random Circles with Randomly Assigned Centers and Radii'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgpWXykmsKLB_zJsUhNqKM9tZqpORKex4FV5Ecs4fyktp5bKKekp2DhIZjttFEViyvJgzj9c_nSliZZ7OV0ggBaH3sIpwp1A7jx8lzWq4h2z7MS_2ASTGpm-2Hc9B4FysWhSvOKwKeVL_rAk4qsvqJJmPzkJkL0R8DeBO-WIzbrf6B5xwoapnwSnObr=s72-w387-h400-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-3950097843830282310</id><published>2023-02-20T22:41:00.008+08:00</published><updated>2023-04-10T16:03:36.143+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Julia"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><title type='text'>Mathematica 教學：Call Julia from Mathematica</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;359&quot; data-original-width=&quot;360&quot; height=&quot;398&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh1bMXsI7IIzI-6ZUqFlmClgIENOOrqU2IVGBxfVh8kXRhEBukkRa4LDn2GRULHfFmIxxle6AkfdVkkXxfa1r60Iq-9oLUYi7hD3UMshzJQaBZ3vf9YR7QOgD8PEZrMJfk8wpm1iECKL_G6g9S65EKVLO3lEgqi0vR6ydFIWhPgRnBUHI-SNy7Q4rZi=w400-h398&quot; width=&quot;400&quot; /&gt;&lt;/div&gt;&lt;pre class=&quot;prettyprint&quot;&gt;session=StartExternalSession[&quot;Julia&quot;]
test =
  &quot;function testpi(size)
    sample = rand(size, 2)
    dist = broadcast(hypot, sample[:,1], sample[:,2])
    return sample, dist
end&quot;;
pitest=ExternalEvaluate[session,test]
size=100000
data=pitest[size];
ListPlot[GatherBy[Transpose[data[[1]]],Norm[#]&lt;1&amp;],Frame -&gt;True,AspectRatio -&gt; 1]
Length@GatherBy[Transpose[data[[1]]], Norm[#]&lt;1&amp;][[1]]/size//N




\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{ifthen}
\begin{document}
  \begin{tikzpicture}
	\draw[help lines, color=gray!30, dashed] (-1.2,1.5) grid (-1.2,1.5);
	\draw[-&gt;] (-1.2,0)--(1.1,0) node[right]{$x$};
	\draw[-&gt;] (0,-1.2)--(0,1.5) node[above]{$y$};
	\draw[domain=0:1, smooth, variable=\x, black] plot ({\x}, {sqrt(1-\x*\x)});
  \pgfmathsetseed{42}
    \foreach \i in {1,...,10000}
    {
      \pgfmathsetmacro{\x}{abs(rand)}
      \pgfmathsetmacro{\y}{abs(rand)}
      \pgfmathsetmacro{\r}{\x*\x+\y*\y}
       \pgfmathsetmacro{\col}{ifthenelse(\r&lt;1,&quot;blue!90&quot;,&quot;red!90&quot;)}
      \fill[\col] (\x,\y) circle (0.1pt)
      ;
    }
  \end{tikzpicture}
\end{document}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/3950097843830282310/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-call-julia-from-mathematica.html#comment-form' title='3 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/3950097843830282310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/3950097843830282310'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-call-julia-from-mathematica.html' title='Mathematica 教學：Call Julia from Mathematica'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEh1bMXsI7IIzI-6ZUqFlmClgIENOOrqU2IVGBxfVh8kXRhEBukkRa4LDn2GRULHfFmIxxle6AkfdVkkXxfa1r60Iq-9oLUYi7hD3UMshzJQaBZ3vf9YR7QOgD8PEZrMJfk8wpm1iECKL_G6g9S65EKVLO3lEgqi0vR6ydFIWhPgRnBUHI-SNy7Q4rZi=s72-w400-h398-c" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-8052715154955270521</id><published>2023-02-12T16:54:00.003+08:00</published><updated>2023-02-15T13:12:59.740+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deterministic cake eating problem"/><category scheme="http://www.blogger.com/atom/ns#" term="Dynamic programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="Polic function iterations"/><title type='text'>Mathematica 教學：Policy function iterations for deterministic cake eating problem</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;445&quot; data-original-width=&quot;450&quot; height=&quot;395&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhTJwE2VkexsozY2SusVZmNMCR9W5AKaxElVwkxlBZLjuQUObIHNanTcY7gqdTMEW1GsXsL4pN1I6RxxObc04z_jzkUzM3qiumFzYx1gv2DzIxDIpOgCJ5BaQjm0Aa0tkQNlDm7wgBVzPosQkB8T3rfLCBNa-ucbqusrf0NJXrzYllKzu-V408Ix8uw=w400-h395&quot; width=&quot;400&quot; /&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;Policy function iterations方法是通過計算出最佳化問題的每一步所實現的最佳結果，並將這些結果用於計算下一步的最佳結果。此過程在一定數量的迭代後會得到一個最佳策略，並且這個策略也是最終的最佳解。因此它對於解決複雜的最佳化問題非常有用。它可以被用於解決各種經濟學、工程學和其他領域的最佳化問題。

&lt;pre class=&quot;prettyprint&quot;&gt;
ClearAll[&quot;Global`*&quot;]
\[Alpha]=0.3;
\[Beta]=0.95;
\[Delta]=0.1;
\[Sigma]=1.5;

size=99;

K=Range[0.1,5,4.9/(size)];
V=Table[0,{size}];


astHoward=With[{n=size},
obj=ParallelTable[If[i^\[Alpha]+(1-\[Delta])*i-j&lt;0,-10^9,
((i^\[Alpha]+(1-\[Delta])*i-j)^(1-\[Sigma])-1)/(1-\[Sigma])],
{i,0.1,5,4.9/n},{j,0.1,5,4.9/n}];
loops=0;
\[Epsilon]=99999;

Print[Grid[{
{&quot;loop number &quot;,
Dynamic[loops],
&quot; with distance &quot;,
Dynamic[NumberForm[\[Epsilon],
ExponentFunction-&gt;(If[-10&lt;#&lt;10,Null,#]&amp;)]]}}]];

NestWhile[
NestWhile[
Transpose@
Table[{obj[[i,#[[2,i]]]]+\[Beta]*#[[1,#[[2,i]]]],#[[2,i]]},{i,Length[#[[1]]]}]&amp;,
Transpose[SortBy[#,First][[-1]]&amp;/@
Table[{obj[[i,j]]+\[Beta]*#[[1,j]],j},{i,n+1},{j,n+1}]//Parallelize],
Norm[#1[[1]]-#2[[1]]]&gt;10^-6&amp;,2]&amp;,
{Table[0,n+1],Table[0,n+1]},
(loops++;\[Epsilon]=Norm[#1[[1]]-#2[[1]]];
Norm[#1[[1]]-#2[[1]]]&gt;10^-6)&amp;,2]
]


astHowardMatrix=With[{n=size},
obj=ParallelTable[If[i^\[Alpha]+(1-\[Delta])*i-j&lt;
0,-10^9,((i^\[Alpha]+(1-\[Delta])*i-j)^(1-\[Sigma])-1)/(1-\[Sigma])],
{i,0.1,5,4.9/n},{j,0.1,5,4.9/n}];
loops=0;
\[Epsilon]=99999;

Id=IdentityMatrix[size+1];

Print[Grid[{
{&quot;loop number &quot;,
Dynamic[loops],
&quot; with distance &quot;,
Dynamic[NumberForm[\[Epsilon],
ExponentFunction-&gt;(If[-10&lt;#&lt;10,Null,#]&amp;)]]}}]];


NestWhile[
(
myValue=Transpose[SortBy[#,First][[-1]]&amp;/@
Table[{obj[[i,j]]+\[Beta]*#[[1,j]],j},{i,n+1},{j,n+1}]//Parallelize];
{Inverse[(Id-\[Beta]*Normal[SparseArray[
Rule[#,1]&amp;/@Transpose[
{Range[size+1],myValue[[2]]}],size+1]])].(obj[[#[[1]],#[[2]]]]&amp;/@
Transpose[{Range[size+1],myValue[[2]]}]),myValue[[2]]}
)&amp;,
{Table[0,n+1],Table[0,n+1]},
(loops++;\[Epsilon]=Norm[#1[[1]]-#2[[1]]];
Norm[#1[[1]]-#2[[1]]]&gt;10^-6)&amp;,2]
]


ListLinePlot[astHowardMatrix[[1]],PlotRange-&gt;All,AspectRatio-&gt;1,Frame-&gt;True]
ListLinePlot[astHowardMatrix[[2]],PlotRange-&gt;All,AspectRatio-&gt;1,Frame-&gt;True]

&lt;/pre&gt; </content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/8052715154955270521/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-policy-function-iterations.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/8052715154955270521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/8052715154955270521'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-policy-function-iterations.html' title='Mathematica 教學：Policy function iterations for deterministic cake eating problem'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhTJwE2VkexsozY2SusVZmNMCR9W5AKaxElVwkxlBZLjuQUObIHNanTcY7gqdTMEW1GsXsL4pN1I6RxxObc04z_jzkUzM3qiumFzYx1gv2DzIxDIpOgCJ5BaQjm0Aa0tkQNlDm7wgBVzPosQkB8T3rfLCBNa-ucbqusrf0NJXrzYllKzu-V408Ix8uw=s72-w400-h395-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5188234340468322713</id><published>2023-02-03T22:01:00.010+08:00</published><updated>2025-07-30T15:27:02.193+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deterministic cake eating problem"/><category scheme="http://www.blogger.com/atom/ns#" term="Dynamic programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="Value function iterations"/><title type='text'>Mathematica 教學：Value function iterations for deterministic cake eating problem</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;282&quot; data-original-width=&quot;450&quot; height=&quot;251&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgldLUx_ThzjHyihBLpmjOXA4Txnaym06PF5PRpP9soCdzKl7xlvay3Cz_VZ0_zoA9vT0AqScHfRsFv1EwySbmu0iBIEJJ_z7TRevgw0UpPtuPHo_64pc82YWh8HSsodSL0H3ZkCim6_wpfZXni_CcP4xtUUr1v2daZ3Vf-NaJOcjIWZGTKKIxRD7UV=w400-h251&quot; width=&quot;400&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;


Value function iterations方法是通過計算出最佳化問題的每一步所實現的最佳結果，並將這些結果用於計算下一步的最佳結果。此過程在一定數量的迭代後會得到一個最佳策略，並且這個策略也是最終的最佳解。因此它對於解決複雜的最佳化問題非常有用。它可以被用於解決各種經濟學、工程學和其他領域的最佳化問題。

&lt;pre class=&quot;prettyprint&quot;&gt;
ClearAll[\[Beta],\[Gamma],xGrid,u,v0];

(*Parameters*)
\[Beta]=0.96;
\[Gamma]=1.5;
xMin=10^-3;
xMax=2.5;
nGrid=120;
xGrid=Subdivide[xMin,xMax,nGrid-1];

(*Utilityfunction*)
u[c_]:=If[\[Gamma]==1,Log[c],(c^(1-\[Gamma]))/(1-\[Gamma])];

(*Initialguess*)
v0=Table[0,{x,xGrid}];

(* Bellman Operator T *)
myT[v_List]:=Block[{myf,x},
myf[x_]=Interpolation[Transpose@{xGrid,v},InterpolationOrder-&gt;1][x];
Max/@Quiet@Table[
(c^(1-\[Gamma]))/(1-\[Gamma])+\[Beta]*myf[x-c],
{x,xGrid},{c,Select[xGrid,#&lt;=x&amp;]}
]];

(* Value Function Iteration using NestWhile *)
myvfi=NestWhileList[myT,v0,Norm[#1-#2]&gt;=0.00001&amp;,2];

(* Plotting the results *)
ListLinePlot[Transpose[{xGrid,#}]&amp;/@myvfi[[2;;-1]]]
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5188234340468322713/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-value-function-iterations.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5188234340468322713'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5188234340468322713'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2023/02/mathematica-value-function-iterations.html' title='Mathematica 教學：Value function iterations for deterministic cake eating problem'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgldLUx_ThzjHyihBLpmjOXA4Txnaym06PF5PRpP9soCdzKl7xlvay3Cz_VZ0_zoA9vT0AqScHfRsFv1EwySbmu0iBIEJJ_z7TRevgw0UpPtuPHo_64pc82YWh8HSsodSL0H3ZkCim6_wpfZXni_CcP4xtUUr1v2daZ3Vf-NaJOcjIWZGTKKIxRD7UV=s72-w400-h251-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5376555941746015217</id><published>2022-05-25T23:50:00.011+08:00</published><updated>2023-02-12T01:29:01.010+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica"/><category scheme="http://www.blogger.com/atom/ns#" term="動態幾何繪圖"/><category scheme="http://www.blogger.com/atom/ns#" term="動態操作介面"/><category scheme="http://www.blogger.com/atom/ns#" term="圖表可視化"/><category scheme="http://www.blogger.com/atom/ns#" term="教學講義"/><category scheme="http://www.blogger.com/atom/ns#" term="數值運算"/><category scheme="http://www.blogger.com/atom/ns#" term="數量方法"/><category scheme="http://www.blogger.com/atom/ns#" term="科學運算"/><category scheme="http://www.blogger.com/atom/ns#" term="符號運算"/><title type='text'>Mathematica 教學講義</title><content type='html'> &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2S_uQYH8rww_zMIGG-pXesNFZxElVvo3cogEo19oBl7Wfw9MwAabTKyAm4sufF9U9RVcMASuFgQ6o9f3CAs7bh5BpsrKult3bSS5iDM8XdaUvQVA3IN5nqyFlOCS-PUCgMg7ai6wv1r5LxmQant5QUAnqUQZ9r_JIXkvDVvrRQQFtcDLp2GNACWVj/s3508/Mathematica.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;Mathematica 教學講義&quot; border=&quot;0&quot; data-original-height=&quot;3508&quot; data-original-width=&quot;2479&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2S_uQYH8rww_zMIGG-pXesNFZxElVvo3cogEo19oBl7Wfw9MwAabTKyAm4sufF9U9RVcMASuFgQ6o9f3CAs7bh5BpsrKult3bSS5iDM8XdaUvQVA3IN5nqyFlOCS-PUCgMg7ai6wv1r5LxmQant5QUAnqUQZ9r_JIXkvDVvrRQQFtcDLp2GNACWVj/w283-h400/Mathematica.png&quot; title=&quot;Mathematica 教學講義&quot; width=&quot;283&quot; /&gt;&lt;/a&gt; 
  
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;background-color: transparent; text-align: left;&quot;&gt;這是我這幾年來數量方法這一門課所自編的 Mathematica 入門教學講義。Mathematica 相較於其他軟體的特點在於強大的符號運算及動態幾何繪圖的科學運算能力。此外，Mathematica 尚包含數值運算、圖表可視化、動態操作介面等。由於擁有許多的內建程式語言及內建系統，故不需要繁雜且複雜的編寫，有能夠輕易上手的便利性。&lt;/span&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC;&quot;&gt;本教學講義相關檔案、資料檔及未來更新維護皆可由下列網址下載：&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: LXGWWenKaiTC; font-size: 16px;&quot;&gt;&lt;a href=&quot;https://github.com/chungyuandye/Mathematica/blob/main/math.pdf&quot;&gt;https://github.com/chungyuandye/Mathematica&lt;/a&gt;&lt;/span&gt;&lt;/div&gt; </content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5376555941746015217/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2016/02/mathematica.html#comment-form' title='1 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5376555941746015217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5376555941746015217'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2016/02/mathematica.html' title='Mathematica 教學講義'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2S_uQYH8rww_zMIGG-pXesNFZxElVvo3cogEo19oBl7Wfw9MwAabTKyAm4sufF9U9RVcMASuFgQ6o9f3CAs7bh5BpsrKult3bSS5iDM8XdaUvQVA3IN5nqyFlOCS-PUCgMg7ai6wv1r5LxmQant5QUAnqUQZ9r_JIXkvDVvrRQQFtcDLp2GNACWVj/s72-w283-h400-c/Mathematica.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-6741441187840910487</id><published>2022-05-11T20:21:00.009+08:00</published><updated>2023-01-28T21:37:09.462+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Teaching"/><title type='text'>青春啊！</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;416&quot; data-original-width=&quot;1505&quot; height=&quot;176&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEj5S4ivQBXqXBMlvaHnFNmRvtr1Az4ZAtpGJPsuEiJ1X-Js1BxNCSvbvkSVtOdDKelmP9TBVbZ68MDc2JMqYBIEL-q1TJuss5IEzEpBbIhkfF-KwsoBVJ5lZh12v1TwEGW6vfFoiHMNq23gSeqYfCIwq4rF2KqlF3swsFVTSLhms3L25vwXzhv56zFJ=w640-h176&quot; width=&quot;640&quot; /&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;帳號被盜走，上站6000次，我的青春啊！&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2023年1月28日，失而復得。&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiiIUxPI2wksqzquNjjMAW-BnDwnmwI_71KoX_7n2UznUyIDLMLodvj5Vp53RBNPJQcvx9dRGXogistv_VRiTjlMhILPrUa5GPz-raiR7p9Wx4quhe-y1EbAnI3xKisOXGqJa644BBzvsXff892lgxxAc1X5V6tu8YpgCEgYjNaAfQYRPPIWTbZ8Tqm&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;1336&quot; data-original-width=&quot;1950&quot; height=&quot;438&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiiIUxPI2wksqzquNjjMAW-BnDwnmwI_71KoX_7n2UznUyIDLMLodvj5Vp53RBNPJQcvx9dRGXogistv_VRiTjlMhILPrUa5GPz-raiR7p9Wx4quhe-y1EbAnI3xKisOXGqJa644BBzvsXff892lgxxAc1X5V6tu8YpgCEgYjNaAfQYRPPIWTbZ8Tqm=w640-h438&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/6741441187840910487/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2022/05/blog-post.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/6741441187840910487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/6741441187840910487'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2022/05/blog-post.html' title='青春啊！'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEj5S4ivQBXqXBMlvaHnFNmRvtr1Az4ZAtpGJPsuEiJ1X-Js1BxNCSvbvkSVtOdDKelmP9TBVbZ68MDc2JMqYBIEL-q1TJuss5IEzEpBbIhkfF-KwsoBVJ5lZh12v1TwEGW6vfFoiHMNq23gSeqYfCIwq4rF2KqlF3swsFVTSLhms3L25vwXzhv56zFJ=s72-w640-h176-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-6528741772009796285</id><published>2022-04-26T21:33:00.036+08:00</published><updated>2022-06-08T08:10:04.395+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CFA"/><category scheme="http://www.blogger.com/atom/ns#" term="JASP教學"/><category scheme="http://www.blogger.com/atom/ns#" term="SEM"/><category scheme="http://www.blogger.com/atom/ns#" term="Teaching"/><category scheme="http://www.blogger.com/atom/ns#" term="統計學講義"/><category scheme="http://www.blogger.com/atom/ns#" term="論文免擔心"/><title type='text'>用 JASP 輕鬆學 SEM:從基礎到應用</title><content type='html'> &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JqCFkRpEXTA73xz6F0ZHjh2gYTz5kMjdWNRpDI0143lTCuje7og8mBnXdgVCBHtjJPH0QlhYd_em_GxMUQ7fsyZ7MAzHhn6ovhxMyhGT-bUSQn4crkUa-Y1yukWbGoexO5wGoNqRrDdyP_hwAEFS88KMagPQp4UEhxryfno_6GCC4e5JIsn4LF6Y/s5200/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2022_3_29_%E4%B8%8A%E5%8D%8810_30.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;3291&quot; data-original-width=&quot;5200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JqCFkRpEXTA73xz6F0ZHjh2gYTz5kMjdWNRpDI0143lTCuje7og8mBnXdgVCBHtjJPH0QlhYd_em_GxMUQ7fsyZ7MAzHhn6ovhxMyhGT-bUSQn4crkUa-Y1yukWbGoexO5wGoNqRrDdyP_hwAEFS88KMagPQp4UEhxryfno_6GCC4e5JIsn4LF6Y/s400/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2022_3_29_%E4%B8%8A%E5%8D%8810_30.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; 

&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;JASP 統計軟體是由阿姆斯特丹大學 &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LMRoman12&#39;; font-size: 12pt;&quot;&gt;Eric-Jan Wagenmakers &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;教授領導的團隊，以 &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LMRoman12&#39;; font-size: 12pt;&quot;&gt;R &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;為核心所開發的
免費開源統計軟體，主要應用於心理及統計分析，相關的分析模組包含:平均數比較、實驗設計、&lt;/span&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;迴歸與相關分析、探索性因素分析、驗證性因素分析（CFA）、結構方程式（SEM）、機械學習、神經網路等。&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;由於其設計理念為讓用戸熟悉並易於使用，故幾乎所有的分析模組都已視窗化，僅需要懂得相關的統計理論卽可輕易上手。有關 &lt;/span&gt;&lt;span style=&quot;font-family: LMRoman12; font-size: 12pt;&quot;&gt;JASP &lt;/span&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;統計軟體的詳細説明可到官方網站參閲，&lt;/span&gt;&lt;span style=&quot;color: magenta; font-family: LMMono12; font-size: 12pt;&quot;&gt;&lt;a href=&quot;https://jasp-stats.org/&quot;&gt;https://jasp-stats.org/&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;。&lt;/span&gt;&lt;span style=&quot;font-family: LMRoman12; font-size: 12pt;&quot;&gt;JASP &lt;/span&gt;&lt;span style=&quot;font-family: LXGWWenKaiTC; font-size: 12pt;&quot;&gt;統計軟體亦可由網站免費下載:&amp;nbsp;&lt;/span&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: magenta; font-family: LMMono12; font-size: 12pt;&quot;&gt;&lt;a href=&quot;https://jasp-stats.org/download/&quot;&gt;https://jasp-stats.org/download/&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
		
	
 本年度統計分析教材以&lt;span style=&quot;font-family: &#39;LMRoman12&#39;; font-size: 12pt;&quot;&gt;JASP &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;講義為主，JASP 統計軟體除了是免費開源外，該軟體以視窗的為主，學生只要能了解課堂上講授的統計分析及進階的驗證性因素分析、競爭模式、多群組比較、結構方程模型的理論後，卽可輕易執行上手。此外，&lt;/span&gt;&lt;span style=&quot;font-family: &#39;LMRoman12&#39;; font-size: 12pt;&quot;&gt;JASP &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;統計軟體所産生的報表
及圖形皆以 &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LMRoman12&#39;; font-size: 12pt;&quot;&gt;APA &lt;/span&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;格式輸出，學生也能因此免除在茫茫報表中重新整理資料、繪製圖形，簡化發
表硏究成果及撰寫論文的流程。本教材相關檔案、資料檔及未來更新維護皆可由下列網址下載:&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;https://github.com/chungyuandye/JASP-&quot;&gt;&lt;span style=&quot;font-family: &#39;LXGWWenKaiTC&#39;; font-size: 12pt;&quot;&gt;&lt;/span&gt;&lt;span color=&quot;rgb(100.000000%, 0.000000%, 100.000000%)&quot; style=&quot;font-family: &#39;LMMono12&#39;; font-size: 12pt;&quot;&gt;https://github.com/chungyuandye/JASP-&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
 &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivC4Q0oXJY8DPIw3YU9CWKamOWo89MSTsHDH6bcXw7A-mQrfFrzcPbimvGJSCZFMph7kbapIkZ9O2_yx88l6OP1inCHl8_ju6fHaitKWiwl9QavZ4rRfQjXjgFwlWa9ucK8fbQLkRbL21TA6s0IzRM6FGrEt0cuqRzjN8oMtdhvcmAhO_DSJOiSnh0/s7015/jasp%EF%BC%88%E5%B7%B2%E6%8B%96%E7%A7%BB%EF%BC%89.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;7015&quot; data-original-width=&quot;4960&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivC4Q0oXJY8DPIw3YU9CWKamOWo89MSTsHDH6bcXw7A-mQrfFrzcPbimvGJSCZFMph7kbapIkZ9O2_yx88l6OP1inCHl8_ju6fHaitKWiwl9QavZ4rRfQjXjgFwlWa9ucK8fbQLkRbL21TA6s0IzRM6FGrEt0cuqRzjN8oMtdhvcmAhO_DSJOiSnh0/s400/jasp%EF%BC%88%E5%B7%B2%E6%8B%96%E7%A7%BB%EF%BC%89.png&quot; /&gt;&lt;/a&gt; 

 </content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/6528741772009796285/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2022/04/jasp-sem.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/6528741772009796285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/6528741772009796285'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2022/04/jasp-sem.html' title='用 JASP 輕鬆學 SEM:從基礎到應用'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JqCFkRpEXTA73xz6F0ZHjh2gYTz5kMjdWNRpDI0143lTCuje7og8mBnXdgVCBHtjJPH0QlhYd_em_GxMUQ7fsyZ7MAzHhn6ovhxMyhGT-bUSQn4crkUa-Y1yukWbGoexO5wGoNqRrDdyP_hwAEFS88KMagPQp4UEhxryfno_6GCC4e5JIsn4LF6Y/s72-c/%E8%B2%BC%E4%B8%8A%E7%9A%84%E5%BD%B1%E5%83%8F_2022_3_29_%E4%B8%8A%E5%8D%8810_30.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-1967818140812254179</id><published>2022-01-28T22:03:00.003+08:00</published><updated>2022-01-28T22:03:51.776+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mac"/><title type='text'>Reduce PDF file size for Mac</title><content type='html'>&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgSpt2ZXFdjLeeeQrhfHNabYp0OsPeveaoZL2BLUniADFxfTnhSUK7JnuIgnYrv1a04C13C9YGAkz_pcpRoBOA1pC764OklfJOrEhYQK34RSwZU4ZohPntidveB6U_sBlw_jvLBHKU9ttP4yYD6u7XApDvo40m00VxQPFwLUuz3JWjPhLWDkGhKcqzb=s1394&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;1040&quot; data-original-width=&quot;1394&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgSpt2ZXFdjLeeeQrhfHNabYp0OsPeveaoZL2BLUniADFxfTnhSUK7JnuIgnYrv1a04C13C9YGAkz_pcpRoBOA1pC764OklfJOrEhYQK34RSwZU4ZohPntidveB6U_sBlw_jvLBHKU9ttP4yYD6u7XApDvo40m00VxQPFwLUuz3JWjPhLWDkGhKcqzb=s400&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;

Mac PDF檔案縮小檔案大小：檔案➡輸出➡Quartz濾鏡➡Reduce file size。 
  
  &lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEir7QS3ucTOokFeyI4CpdVof73m_w66uVlx0oMjAs15iMPKwam01xmqR3ULWdMGxxyZyv597rHNWNmRumMHQpfJyxDCbpJT1H7KeXQlM0aB3Qu0XMy_7MLrDl0ngmmIVa2nXTnVy-gYtoY8igqBFrANf6-3V42jSb1jq8ZbuWRB7FnF9H3D9xkyPQTl=s1388&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;1038&quot; data-original-width=&quot;1388&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEir7QS3ucTOokFeyI4CpdVof73m_w66uVlx0oMjAs15iMPKwam01xmqR3ULWdMGxxyZyv597rHNWNmRumMHQpfJyxDCbpJT1H7KeXQlM0aB3Qu0XMy_7MLrDl0ngmmIVa2nXTnVy-gYtoY8igqBFrANf6-3V42jSb1jq8ZbuWRB7FnF9H3D9xkyPQTl=s400&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; </content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/1967818140812254179/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2022/01/reduce-pdf-file-size-for-mac.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1967818140812254179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1967818140812254179'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2022/01/reduce-pdf-file-size-for-mac.html' title='Reduce PDF file size for Mac'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgSpt2ZXFdjLeeeQrhfHNabYp0OsPeveaoZL2BLUniADFxfTnhSUK7JnuIgnYrv1a04C13C9YGAkz_pcpRoBOA1pC764OklfJOrEhYQK34RSwZU4ZohPntidveB6U_sBlw_jvLBHKU9ttP4yYD6u7XApDvo40m00VxQPFwLUuz3JWjPhLWDkGhKcqzb=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-7833452489454094581</id><published>2022-01-23T14:41:00.005+08:00</published><updated>2022-01-23T15:02:35.013+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 畫圖"/><title type='text'>111學測數A第18題</title><content type='html'>&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjKWkncADzT7-lX0avxRMyudX56aXP_JDcXHt0ySlArAExCDOdZsBo8H6W4uE2yXicchWSCQcsDKwrrTeTPatw5PKCsW0iFl3qt9-Cq6KTe1CXOM7BcEmQDWRJ-nHWUNHMKrpRXBRnHx0ExIYAFa5t1l9xbXmAJ4bH4yHB0SmkrAHBsM9TgRG_90V-m=s250&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;135&quot; data-original-width=&quot;250&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjKWkncADzT7-lX0avxRMyudX56aXP_JDcXHt0ySlArAExCDOdZsBo8H6W4uE2yXicchWSCQcsDKwrrTeTPatw5PKCsW0iFl3qt9-Cq6KTe1CXOM7BcEmQDWRJ-nHWUNHMKrpRXBRnHx0ExIYAFa5t1l9xbXmAJ4bH4yHB0SmkrAHBsM9TgRG_90V-m=s400&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;

利用三角板(30°-60°-90°)轉半圈即可。
&lt;pre class=&quot;prettyprint&quot;&gt;pt[x0_]:={{0,0},{x0,Sqrt[4-x0^2]},{x,Sqrt[3-x^2]},{0,0}}/.
Quiet@Solve[{x^2+y^2==3,(x-x0)^2+(y-Sqrt[4-x0^2])^2==1},{x,y}][[2]]

Manipulate[
Plot[{Sqrt[4-x^2],Sqrt[3-x^2]},{x,-2,2},AspectRatio-&amp;gt;1/2,
Epilog-&amp;gt;{Green,Thickness[0.005],
Line[pt[Sqrt[3+10^(-7)]][[1;;3]]],
Red,PointSize[0.02],Point[pt[Sqrt[3+10^(-7)]]],
Point[pt[z][[1;;3]]],
Blue,Line[pt[z][[1;;2]]],Line[pt[z][[2;;3]]],
Line[pt[z][[3;;4]]]}
],{z,Sqrt[3]+10^(-7),-2}]

Integrate[Sqrt[4-x^2]-Sqrt[3-x^2],{x,0,Sqrt[3]}]

Integrate[Sqrt[4-x^2]-Sqrt[3](2+x),{x,-2,-(3/2)}]+
Integrate[Sqrt[4-x^2]-Sqrt[3-x^2],{x,-(3/2),Sqrt[3]}]//FullSimplify
&lt;/pre&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhv_qke93Ja4QdDSLcyN2RDMJhghXLfJGi3h-xL7BT3GMUWMWZj05ajuR-4u51mZv376OGvPTG1GpMLtnXo1Y-QT_PnSqLmFLcP1d3wwv06ky-Sbg7Kb107JhSKsjE8ZBaVNMCpcIQuN2pERE9UdgxZ_cKlQEru-z3bgmqON97HqRHDqGXjsCwW1KfT=s854&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;854&quot; data-original-width=&quot;660&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhv_qke93Ja4QdDSLcyN2RDMJhghXLfJGi3h-xL7BT3GMUWMWZj05ajuR-4u51mZv376OGvPTG1GpMLtnXo1Y-QT_PnSqLmFLcP1d3wwv06ky-Sbg7Kb107JhSKsjE8ZBaVNMCpcIQuN2pERE9UdgxZ_cKlQEru-z3bgmqON97HqRHDqGXjsCwW1KfT=s400&quot; /&gt;&lt;/a&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/7833452489454094581/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2022/01/111a18.html#comment-form' title='1 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7833452489454094581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/7833452489454094581'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2022/01/111a18.html' title='111學測數A第18題'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjKWkncADzT7-lX0avxRMyudX56aXP_JDcXHt0ySlArAExCDOdZsBo8H6W4uE2yXicchWSCQcsDKwrrTeTPatw5PKCsW0iFl3qt9-Cq6KTe1CXOM7BcEmQDWRJ-nHWUNHMKrpRXBRnHx0ExIYAFa5t1l9xbXmAJ4bH4yHB0SmkrAHBsM9TgRG_90V-m=s72-c" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-2165038208996580960</id><published>2021-07-08T14:49:00.005+08:00</published><updated>2021-07-08T23:23:00.782+08:00</updated><title type='text'>Mathematica 教學：Factor analysis with Varimax rotation</title><content type='html'> &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOMRJut2MIDEw63E5K_4Eu9gQkDE0tlIi7x0RE9ZE_T-4pXFUIg79n0moxdtP5Ry4ejX-7tr0b_AtMj05YSYq0ro9zn53AO3cGAXJLxIb7G2k7Gw2RgKlzRkqH3Suz5ZkLDQyEgYL_trM/s1469/212752938_10215787706324624_5069398452006103245_n.jpeg&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;1469&quot; data-original-width=&quot;961&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOMRJut2MIDEw63E5K_4Eu9gQkDE0tlIi7x0RE9ZE_T-4pXFUIg79n0moxdtP5Ry4ejX-7tr0b_AtMj05YSYq0ro9zn53AO3cGAXJLxIb7G2k7Gw2RgKlzRkqH3Suz5ZkLDQyEgYL_trM/s320/212752938_10215787706324624_5069398452006103245_n.jpeg&quot; /&gt;&lt;/a&gt; 

&lt;pre class=&quot;prettyprint&quot;&gt;varimax[data_]:=Block[{AA,BB,CC,DD,nn,uu,XX,YY,vdata,angle,Tr,temp,vlist},
{nn,uu}=Dimensions[data];
vdata=Map[Normalize,data];
Do[
angle=Arg[nn* Total[Thread[Complex[
vdata[[All,iter[[1]]]],vdata[[All,iter[[2]]]]]]^4]
-Total[Thread[Complex[
vdata[[All,iter[[1]]]],vdata[[All,iter[[2]]]]]]^2]^2]/4;
Tr={{Cos[angle],-Sin[angle]},{Sin[angle],Cos[angle]}};
vdata[[All,iter]]= vdata[[All,iter]].Tr,
{iter,Flatten[Subsets[Range[uu],{2}]&amp;amp;/@Range[25],1]}
];
vdata*(Norm[#]&amp;amp;/@data)];


myfactor[data_]:=Block[{label,fadata,mypca,loadings,nf,rotatedloadings,
rotatedfactor,ncfa,proddata},
label=data[[1]];
fadata=data[[2;;-1]];
mypca=Eigensystem[Correlation@fadata];
nf=Length[Select[mypca[[1]],#&amp;gt;=1&amp;amp;]];
loadings=Transpose[mypca[[1,#]]^0.5*mypca[[2,#]]&amp;amp;/@Range[nf]];
rotatedloadings=varimax[loadings];
loadings=Flatten@{#,rotatedloadings[[#]],&quot;&quot;,&quot;&quot;}&amp;amp;/@Range[Length@loadings];
rotatedfactor=Table[Select[loadings,
(Abs[#[[i]]]==Max[Map[Abs,#[[2;;1+nf]]]])&amp;amp;],{i,2,nf+1}];
(rotatedfactor[[#,1,nf+2]]=mypca[[1,#]];
rotatedfactor[[#,1,nf+3]]=PercentForm[
Accumulate[mypca[[1]]][[#]]/Total[mypca[[1]]]];)&amp;amp;/@Range[nf];

Print[&quot;\n探索性因素分析\n&quot;];

Print[TableForm[
Flatten[Table[Flatten@{StringReplace[label[[#[[1]]]],&quot; &quot;-&amp;gt;&quot;&quot;],
#[[2;;-1]]}&amp;amp;/@rotatedfactor[[i]],{i,nf}],1],
TableHeadings-&amp;gt;{None, 
Flatten@{&quot;題項&quot;,&quot;因素&quot;&amp;lt;&amp;gt;ToString[#]&amp;amp;/@Range[nf],&quot;特徵根&quot;,&quot;解釋百分比&quot;}}]];
ncfa=Length/@rotatedfactor;
proddata=data[[All,Flatten[#[[All,1]]&amp;amp;/@rotatedfactor]]][[2;;-1]];

Print[&quot;\n驗證性因素分析\n&quot;];

Print@thesisnoworrycfa[
proddata,ncfa,ToExpression[&quot;X&quot;&amp;lt;&amp;gt;ToString[#]]&amp;amp;/@Range[nf]];
];

myfactorcheck[data_]:=Block[{label,fadata,mypca,loadings,nf,
rotatedloadings,rotatedfactor,ncfa,proddata,check,checkfactornum},
label=data[[1]];
fadata=data[[2;;-1]];
mypca=Eigensystem[Correlation@fadata];
nf=Length[Select[mypca[[1]],#&amp;gt;=1&amp;amp;]];
loadings=Transpose[mypca[[1,#]]^0.5*mypca[[2,#]]&amp;amp;/@Range[nf]];
rotatedloadings=varimax[loadings];
loadings=Flatten@{#,rotatedloadings[[#]],&quot;&quot;,&quot;&quot;}&amp;amp;/@Range[Length@loadings];
rotatedfactor=Table[Select[loadings,(Abs[#[[i]]]==Max[Map[Abs,#[[2;;1+nf]]]])&amp;amp;],{i,2,nf+1}];

rotatedfactor=Table[Insert[i,Length[rotatedfactor[[#]]],-1],
{i,rotatedfactor[[#]]}]&amp;amp;/@Range[Length[rotatedfactor]];

check[list_,j_]:=Block[{temp=list},
If[Abs[temp[[1+j]]]&lt;0 .45=&quot;&quot; actor=&quot;&quot; nf=&quot;&quot; temp=&quot;&quot;&gt;ToString[j];
temp[[3+nf]]=&quot;因素負荷過低&quot;,temp[[2+nf]]=&quot;Factor &quot;&amp;lt;&amp;gt;ToString[j];
temp[[3+nf]]=temp[[3+nf]]];temp];
 

check=Flatten[Select[#,#[[-2]]==&quot;因素負荷過低&quot;||#[[-1]]&amp;lt;=2&amp;amp;]&amp;amp;/@Table[
Map[check[#,i]&amp;amp;,rotatedfactor[[i]]],{i,nf}],1];
Print@TableForm@check;

data[[All,Complement[Range[Dimensions[data][[2]]],check[[All,1]]]]]
];

test=Import[&quot;test.xlsx&quot;][[1]][[All,8;;29]];
semmethod=&quot;ML&quot;;
myfactor[NestWhile[myfactorcheck,test,UnsameQ,2]]
&lt;/0&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/2165038208996580960/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2021/07/mathematica-factor-analysis-with.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/2165038208996580960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/2165038208996580960'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2021/07/mathematica-factor-analysis-with.html' title='Mathematica 教學：Factor analysis with Varimax rotation'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOMRJut2MIDEw63E5K_4Eu9gQkDE0tlIi7x0RE9ZE_T-4pXFUIg79n0moxdtP5Ry4ejX-7tr0b_AtMj05YSYq0ro9zn53AO3cGAXJLxIb7G2k7Gw2RgKlzRkqH3Suz5ZkLDQyEgYL_trM/s72-c/212752938_10215787706324624_5069398452006103245_n.jpeg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-151784533110464179</id><published>2021-07-04T09:24:00.019+08:00</published><updated>2021-07-05T14:58:01.668+08:00</updated><title type='text'>Mathematica 教學：Varimax rotation</title><content type='html'> &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg93eaoX3AAatRTBFJxauJcEDeBuMWnUHMTOunRttBCrgLE-eVM8mDEL6MQLq4ua83ajNsunaXpBr4_BcB0svFLcP2Z0ArZ0HtvsXbWhlD2v8BKeq5FjHQcIfxtK0TAvIrqeHMw8XV3ys/s720/Untitled.png&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;698&quot; data-original-width=&quot;720&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg93eaoX3AAatRTBFJxauJcEDeBuMWnUHMTOunRttBCrgLE-eVM8mDEL6MQLq4ua83ajNsunaXpBr4_BcB0svFLcP2Z0ArZ0HtvsXbWhlD2v8BKeq5FjHQcIfxtK0TAvIrqeHMw8XV3ys/s400/Untitled.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; 

&lt;pre class=&quot;prettyprint&quot;&gt;
varimax[data_]:=
Block[{AA,BB,CC,DD,nn,uu,XX,YY,vdata,angle,Tr,temp,vlist},
{nn,uu}=Dimensions[data];
vdata=Map[Normalize,data];
Do[angle=Arg[nn*
Total[Thread[Complex[vdata[[All,iter[[1]]]],
vdata[[All,iter[[2]]]]]]^4]-
Total[Thread[Complex[vdata[[All,iter[[1]]]],
vdata[[All,iter[[2]]]]]]^2]^2]/4;
Tr={{Cos[angle],-Sin[angle]},{Sin[angle],Cos[angle]}};
vdata[[All,iter]]=vdata[[All,iter]].Tr,
{iter,Flatten[Subsets[Range[uu],{2}]&amp;/@Range[25],1]}];
vdata*(Norm[#]&amp;/@data)
]

L = {{-0.18444, 0.766739, -0.27758, 0.115158, 0.712221}, 
{0.698485, -0.30363, -0.19539, -0.2648, 0.688367}, 
{0.754094, 0.348652, -0.20205, -0.30588, 0.824599}, 
{0.365978, 0.162525, -0.1973, 0.849845, 0.92152}, 
{0.5781630, .044134, 0.452722, 0.157895, 0.566108},
{0.299667, 0.030388, 0.770856, 0.063739, 0.689006}, 
{0.817187, 0.239353, -0.19451, -0.16643, 0.79062}, 
{0.687893, 0.035304, 0.116032, 0.117627, 0.501742}, 
{0.301458, -0.74108, -0.3442, 0.233979, 0.81329}};
 

Map[NumberForm[#,{4,3}]&amp;amp;,varimax[L[[All,1;;4]]],{2}]//TableForm


(* Park, T. (2010). A Note on Terse Coding of Kaiser’s Varimax 
Rotation Using Complex Number Representation.*)
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/151784533110464179/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2021/07/mathematica-varimax-rotation.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/151784533110464179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/151784533110464179'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2021/07/mathematica-varimax-rotation.html' title='Mathematica 教學：Varimax rotation'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgg93eaoX3AAatRTBFJxauJcEDeBuMWnUHMTOunRttBCrgLE-eVM8mDEL6MQLq4ua83ajNsunaXpBr4_BcB0svFLcP2Z0ArZ0HtvsXbWhlD2v8BKeq5FjHQcIfxtK0TAvIrqeHMw8XV3ys/s72-c/Untitled.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-1735997441452740027</id><published>2020-08-25T14:09:00.012+08:00</published><updated>2020-08-25T14:19:50.309+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 畫圖"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><title type='text'>Mathematica 教學：Convex Hull</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;360&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZJGNBLM9DVVOpMSYAmphApN3tRFv_4J26pgyJY9JnqLYKg7FRSlyup8lTqmIz0MQhKvQBu5OqTlOwtid69aQr-VN7NNFkXMZ3u84Gg042IKjSa-KDzVqrlA3aBzHljjChoi9iPOLq9Jg/w400-h400/convexhull.png&quot; width=&quot;400&quot; /&gt;&lt;/div&gt;&lt;pre class=&quot;prettyprint&quot;&gt;

splitdata[datatemp___]:=Block[{eqn,temp,x,y,group,vertex,ans},
temp=SortBy[datatemp,Left][[{1,-1}]];
eqn[x_,y_]=y-temp[[1,2]]-
(temp[[1,2]]-temp[[2,2]])/(temp[[1,1]]-temp[[2,1]])(x-temp[[1,1]]);
group={Select[datatemp,eqn[#[[1]],#[[2]]]&gt; 0&amp;],
Select[datatemp,eqn[#[[1]],#[[2]]]&lt; 0&amp;]};

vertex={SortBy[group[[1]],Abs@eqn[#[[1]],#[[2]]]&amp;][[-1]],
SortBy[group[[2]],Abs@eqn[#[[1]],#[[2]]]&amp;][[-1]]};

ans={{{temp[[1]],vertex[[1]]},
Select[group[[1]],RegionMember[
Polygon[Insert[temp,vertex[[1]],-1]],#]==False&amp;&amp;#[[1]]&lt; vertex[[1,1]]&amp;]},
{{temp[[2]],vertex[[1]]},
Select[group[[1]],RegionMember[
Polygon[Insert[temp,vertex[[1]],-1]],#]==False&amp;&amp;#[[1]]&gt; vertex[[1,1]]&amp;]},
{{temp[[1]],vertex[[2]]},
Select[group[[2]],RegionMember[
Polygon[Insert[temp,vertex[[2]],-1]],#]==False&amp;&amp;#[[1]]&lt; vertex[[2,1]]&amp;]},
{{temp[[2]],vertex[[2]]},
Select[group[[2]],RegionMember[
Polygon[Insert[temp,vertex[[2]],-1]],#]==False&amp;&amp;#[[1]]&gt; vertex[[2,1]]&amp;]}
};

If[Length[#[[2]]]==0,{#[[1]],{#[[1,1]]}},{#[[1]],#[[2]]}]&amp;/@ans
];

convexhull[{p1__,p2__},datatemp___]:=Block[{eqn,temp,x,y,group,vertex,ans},
temp=SortBy[{p1,p2},Left];
If[Length[datatemp]==0,{{temp,{}},{temp,{}}},
If[Length[datatemp]==1,{{{temp[[1]],datatemp[[1]]},{}},
{{temp[[2]],datatemp[[1]]},{}}},

eqn[x_,y_]=y-temp[[1,2]]-(temp[[1,2]]-temp[[2,2]])/
(temp[[1,1]]-temp[[2,1]])(x-temp[[1,1]]);

vertex=SortBy[datatemp,Abs@eqn[#[[1]],#[[2]]]&amp;][[-1]];

group={Select[datatemp,#[[1]]&lt; vertex[[1]]&amp;],
Select[datatemp,#[[1]] &gt; vertex[[1]]&amp;]};

ans={{{temp[[1]],vertex},
Select[group[[1]],RegionMember[Polygon[Insert[temp,vertex,-1]],#]==
False&amp;&amp;#[[1]]&lt; vertex[[1]]&amp;]},
{{vertex,temp[[2]]},
Select[group[[2]],RegionMember[Polygon[Insert[temp,vertex,-1]],#]==
False&amp;&amp;#[[1]]&gt; vertex[[1]]&amp;]}}
]]
];

data=RandomReal[NormalDistribution[0,2],{250,2}];
Needs[&quot;ComputationalGeometry`&quot;]

test=splitdata[data];
xx=Nest[Flatten[convexhull@@@#,1]&amp;,test,3];
myline=Line/@Tally[xx[[All,1]]][[All,1]];
mypts=Point@Tally[xx[[All,1]]][[All,1,1]];

ListPlot[data,AspectRatio-&gt;1,
Epilog-&gt;{Red,Thickness[0.015],myline,Blue,PointSize[0.05],mypts}]
 
&lt;/vertex&gt;&lt;/vertex&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/1735997441452740027/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2020/08/mathematica-convex-hull.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1735997441452740027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/1735997441452740027'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2020/08/mathematica-convex-hull.html' title='Mathematica 教學：Convex Hull'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZJGNBLM9DVVOpMSYAmphApN3tRFv_4J26pgyJY9JnqLYKg7FRSlyup8lTqmIz0MQhKvQBu5OqTlOwtid69aQr-VN7NNFkXMZ3u84Gg042IKjSa-KDzVqrlA3aBzHljjChoi9iPOLq9Jg/s72-w400-h400-c/convexhull.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5006592901568157545</id><published>2020-08-03T20:45:00.014+08:00</published><updated>2020-08-03T21:18:18.670+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="中介變數"/><category scheme="http://www.blogger.com/atom/ns#" term="論文免擔心"/><title type='text'>ThesisNoWorries Beta 0.3</title><content type='html'>&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://youtu.be/mNUKHT2K0LU&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1397&quot; data-original-width=&quot;2048&quot; height=&quot;273&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSLc5mefIJENwnuKKn3QXTDPIJ0HTAtayLXVVnsGlzmf5XksH51xDstYttf-d4FG3D3z3I0cV9fwAxmkLpT4AeTnMahaRFvXqfpUbopvVqSgXoPKX5oHmX5hyphenhyphenFgcL4_tmSfCkq7wBN-Wk/w400-h273/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-08-03+%25E4%25B8%258B%25E5%258D%25889.10.50.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;

&amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;論文統計分析免煩惱，平均數比較、迴歸分析、信度、效度 CFA、結構方程是模型 SEM，一鍵搞定！&amp;nbsp;
&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;範例：本研究採量化研究，以XXX為研究對象，發放問卷XXX份，回收有效問卷XXX份，並以三山出版社所提供的 ThesisNoWorries 論文統計分析免煩惱 統計套件進行描述性統計、信效度分析、平均數比較、迴歸和相關分析、及結構方程式模型分析。&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;程式碼：&lt;a href=&quot;https://github.com/chungyuandye/ThesisNoWorries&quot; style=&quot;text-align: center;&quot; target=&quot;_blank&quot;&gt;https://github.com/chungyuandye/ThesisNoWorries&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5006592901568157545/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2020/08/thesisnoworries-beta-03.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5006592901568157545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5006592901568157545'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2020/08/thesisnoworries-beta-03.html' title='ThesisNoWorries Beta 0.3'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSLc5mefIJENwnuKKn3QXTDPIJ0HTAtayLXVVnsGlzmf5XksH51xDstYttf-d4FG3D3z3I0cV9fwAxmkLpT4AeTnMahaRFvXqfpUbopvVqSgXoPKX5oHmX5hyphenhyphenFgcL4_tmSfCkq7wBN-Wk/s72-w400-h273-c/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-08-03+%25E4%25B8%258B%25E5%258D%25889.10.50.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-4872606458065194132</id><published>2020-03-13T11:57:00.001+08:00</published><updated>2020-03-16T11:27:03.734+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><title type='text'>Excel：Calculate ACF and PACF in Excel</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji8o07GDKoNdmS9CGx5qXccJxwXexj2Aa5sNEE54wmXsrTMgWJh8SH8viskG0gQjK7HpkK_f-Mtxf6Xr5mgHHzBFqrte0vRmtp_Y7ZcUm1ey9q7tVMqyo3xPI3BYiCjrq-SxaTG8X9tOI/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-03-13+%25E4%25B8%258A%25E5%258D%258811.56.57.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;531&quot; data-original-width=&quot;494&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji8o07GDKoNdmS9CGx5qXccJxwXexj2Aa5sNEE54wmXsrTMgWJh8SH8viskG0gQjK7HpkK_f-Mtxf6Xr5mgHHzBFqrte0vRmtp_Y7ZcUm1ey9q7tVMqyo3xPI3BYiCjrq-SxaTG8X9tOI/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-03-13+%25E4%25B8%258A%25E5%258D%258811.56.57.png&quot; width=&quot;372&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;Function acf(data As Range, k As Integer) As Double
Dim n As Integer
n = data.Rows.Count
Dim xbar As Double
xbar = Application.Average(data)
Dim sum1 As Double
sum1 = Application.SumProduct(data, data) - n * xbar * xbar
Dim sum2 As Double
sum2 = 0
For i = 1 To n - k
    sum2 = sum2 + (data.Cells(i) - xbar) * (data.Cells(i + k) - xbar)
Next
acf = sum2 / sum1
End Function

Function pacf(data As Range, k As Integer) As Double
Dim xx() As Double
ReDim xx(1 To k, 1 To k) As Double
For i = 1 To k
    For j = 1 To k
        xx(i, j) = acf(data, Abs(j - i))
    Next
Next
Dim yy() As Double
ReDim yy(1 To k, 1 To 1) As Double
For i = 1 To k
    For j = 1 To 1
        yy(i, 1) = acf(data, Abs(i))
    Next
Next 
pacf = Application.Index(Application.MMult(Application.MInverse(xx), yy), k, 1)
End Function
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/4872606458065194132/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2020/03/excelacf-and-pacf.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/4872606458065194132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/4872606458065194132'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2020/03/excelacf-and-pacf.html' title='Excel：Calculate ACF and PACF in Excel'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji8o07GDKoNdmS9CGx5qXccJxwXexj2Aa5sNEE54wmXsrTMgWJh8SH8viskG0gQjK7HpkK_f-Mtxf6Xr5mgHHzBFqrte0vRmtp_Y7ZcUm1ey9q7tVMqyo3xPI3BYiCjrq-SxaTG8X9tOI/s72-c/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-03-13+%25E4%25B8%258A%25E5%258D%258811.56.57.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5000008144058276507</id><published>2020-02-03T12:05:00.001+08:00</published><updated>2020-02-03T12:09:29.163+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="LaTeX"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 畫圖"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><category scheme="http://www.blogger.com/atom/ns#" term="論文免擔心"/><title type='text'>Exporting graphics to TikZ format with Mathematica, Version 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVCcTUqxAClouTFNdnZd9_KNi7FwNQrIJscvp17EM8NNOtLjDHQXA3d4y8QXBG4U-HhSzUdMNpIu96YcgqwNp4i95ro2xTvQVupxVhjfEfdSuNemeJHagTAdeQHtU_y_xBEMiEmge2rM0/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-02-03+%25E4%25B8%258B%25E5%258D%258812.02.44.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;763&quot; data-original-width=&quot;786&quot; height=&quot;388&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVCcTUqxAClouTFNdnZd9_KNi7FwNQrIJscvp17EM8NNOtLjDHQXA3d4y8QXBG4U-HhSzUdMNpIu96YcgqwNp4i95ro2xTvQVupxVhjfEfdSuNemeJHagTAdeQHtU_y_xBEMiEmge2rM0/s400/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-02-03+%25E4%25B8%258B%25E5%258D%258812.02.44.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre class=&quot;prettyprint&quot;&gt;mytwoaxistikz[data__,{xmin_,xmax_,ymin_,ymax_},
mycolor__,{xlabel_,ylabel_},{rticks__,decimalr_,lticks__,decimall_},
linelabel__,linepos__,plotaspectratio_:1]:=Block[{temp=data,axis1,axis2,textpos,line},
axis1=&quot;
\\begin{axis}[
    yticklabel style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=&quot;&lt;&gt;ToString[decimall]&lt;&gt;&quot;,
    },
 scale only axis, 
 axis y line*=left, 
 xtick pos=left, 
 xscale=&quot;&lt;&gt;ToString[N@plotaspectratio]&lt;&gt;&quot;, 
 xmin=&quot;&lt;&gt;ToString[xmin]&lt;&gt;&quot;,xmax=&quot;&lt;&gt;ToString[xmax]&lt;&gt;&quot;,ymin=&quot;&lt;&gt;ToString[ymin]&lt;&gt;
 &quot;,ymax=&quot;&lt;&gt;ToString[ymax]&lt;&gt;&quot;,
 xlabel=&quot;&lt;&gt;xlabel&lt;&gt;&quot;,ylabel=&quot;&lt;&gt;ylabel&lt;&gt;&quot;,
 ytick=&quot;&lt;&gt;ToString[lticks]&lt;&gt;&quot;]\n&quot;;

textpos=StringJoin[Table[&quot;
 \\node[] at (axis cs:&quot;&lt;&gt;ToString[linepos[[z,1]]]&lt;&gt;&quot;,&quot;&lt;&gt;ToString[linepos[[z,2]]]&lt;&gt;
 &quot;) {&quot;&lt;&gt;linelabel[[z]]&lt;&gt;&quot;};&quot;,{z,Length@temp}]];

line=StringJoin[Table[&quot;
\\addplot[color=&quot;&lt;&gt;If[ListQ[mycolor[[z]]],
ToString[mycolor[[z,1]]]&lt;&gt;&quot;,&quot;&lt;&gt;ToString[mycolor[[z,2]]],
ToString[mycolor[[z]]]]&lt;&gt;&quot;,mark=none,line width=0.5mm] coordinates{\n&quot;
 &lt;&gt;StringJoin[&quot;(&quot;&lt;&gt;ToString[#[[1]]]&lt;&gt;&quot;,&quot;&lt;&gt;ToString[#[[2]]]&lt;&gt;&quot;)\n&quot;&amp;/@temp[[z]]]&lt;&gt;
 &quot;};\n\\addlegendentry{$G_{0}= &quot;&lt;&gt;ToString[G0[[z]]]&lt;&gt;&quot;$}&quot;,{z,Length@temp}]]
&lt;&gt;&quot;\n\\end{axis}\n&quot;;

axis2=&quot;\n\\begin{axis}[ 
    yticklabel style={
        /pgf/number format/.cd,
            fixed,
            fixed zerofill,
            precision=&quot;&lt;&gt;ToString[decimalr]&lt;&gt;&quot;,
    },
 scale only axis, 
 axis y line*=right, 
 xtick pos=left, 
 xscale=&quot;&lt;&gt;ToString[N@plotaspectratio]&lt;&gt;&quot;, 
 xmin=&quot;&lt;&gt;ToString[xmin]&lt;&gt;&quot;,xmax=&quot;&lt;&gt;ToString[xmax]&lt;&gt;&quot;,ymin=&quot;&lt;&gt;ToString[ymin]&lt;&gt;
 &quot;,ymax=&quot;&lt;&gt;ToString[ymax]&lt;&gt;&quot;,
 ytick=&quot;&lt;&gt;ToString[rticks]&lt;&gt;&quot;]\n&quot;;

&quot;\\begin{tikzpicture}&quot;&lt;&gt;axis1&lt;&gt;textpos&lt;&gt;line&lt;&gt;axis2&lt;&gt;&quot;\n\\end{axis}\n\\end{tikzpicture}&quot;
]
&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5000008144058276507/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2020/02/exporting-graphics-to-tikz-format-with.html#comment-form' title='1 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5000008144058276507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5000008144058276507'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2020/02/exporting-graphics-to-tikz-format-with.html' title='Exporting graphics to TikZ format with Mathematica, Version 2'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVCcTUqxAClouTFNdnZd9_KNi7FwNQrIJscvp17EM8NNOtLjDHQXA3d4y8QXBG4U-HhSzUdMNpIu96YcgqwNp4i95ro2xTvQVupxVhjfEfdSuNemeJHagTAdeQHtU_y_xBEMiEmge2rM0/s72-c/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7+2020-02-03+%25E4%25B8%258B%25E5%258D%258812.02.44.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5241994033008969844</id><published>2019-11-22T14:25:00.000+08:00</published><updated>2019-11-23T09:54:19.697+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學"/><category scheme="http://www.blogger.com/atom/ns#" term="Mathematica 教學 程式"/><title type='text'>Mathematica 教學：使用 Jupyter Notebook 做為 Mathematica 操作環境</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg91USvBckB1gBf8cD-tlPaf6SjqFzIlxXUxahoRDEOchNvWHky0q2tAzWnEz_qKC3aKc1xapdK10UuDM-Lx9T4JmABB5z_3FK6V4dT6B_c5NDfgFsMdmD5K-1qoAz1ZNkQJlj8_ezqqoU/s1600/75388382_10212228845355324_5629312922179076096_o.jpg&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1381&quot; data-original-width=&quot;1544&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg91USvBckB1gBf8cD-tlPaf6SjqFzIlxXUxahoRDEOchNvWHky0q2tAzWnEz_qKC3aKc1xapdK10UuDM-Lx9T4JmABB5z_3FK6V4dT6B_c5NDfgFsMdmD5K-1qoAz1ZNkQJlj8_ezqqoU/s400/75388382_10212228845355324_5629312922179076096_o.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
安裝 Ijupyter&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;python3 -m pip install --upgrade pip
python3 -m pip install jupyter
&lt;/pre&gt;&lt;br /&gt;
設定遠端連線 jupyter server，在python shell中執行&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;from notebook.auth import passwd; passwd()
&lt;/pre&gt;&lt;br /&gt;
生成修改設定檔&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip=&#39;*&#39; #*表示所有IP，這裡設定ip為都可訪問  
c.NotebookApp.password = &#39;填寫剛剛生成的密文&#39;
c.NotebookApp.open_browser = False # 禁止notebook啟動時自動開啟瀏覽器
c.NotebookApp.port =9999 #指定訪問的埠，預設是8888。 
&lt;/pre&gt;&lt;br /&gt;
下載 configure-jupyter.wls&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/WolframResearch/WolframLanguageForJupyter&quot;&gt;https://github.com/WolframResearch/WolframLanguageForJupyter&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
執行 wolframscript 安裝 WolframLanguageForJupyter&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;wolframscript configure-jupyter.wls add
&lt;/pre&gt;啟動 Jupyter notebook&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5241994033008969844/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2019/11/mathematica-jupyter-notebook-mathematica.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5241994033008969844'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5241994033008969844'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2019/11/mathematica-jupyter-notebook-mathematica.html' title='Mathematica 教學：使用 Jupyter Notebook 做為 Mathematica 操作環境'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg91USvBckB1gBf8cD-tlPaf6SjqFzIlxXUxahoRDEOchNvWHky0q2tAzWnEz_qKC3aKc1xapdK10UuDM-Lx9T4JmABB5z_3FK6V4dT6B_c5NDfgFsMdmD5K-1qoAz1ZNkQJlj8_ezqqoU/s72-c/75388382_10212228845355324_5629312922179076096_o.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6352798839577548669.post-5564040488560792320</id><published>2018-11-17T16:26:00.004+08:00</published><updated>2018-11-17T16:28:50.849+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><title type='text'>Excel 教學：符合條件整列變色</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEjvRqBYK895FxzJjcWUPljh34xTISc2jXCatp0j6bWhyEWoFPrjRo9orfuG3GeC7Ha0Y1RpIA0RrS-IwJ_xxEb9JL7B-68p9blDxXwJWfDBMTz6WzontB11KkU8nIh_pFMp0vAQg7XJ4/s1600/image-784761.png&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_6624742184583309650&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEjvRqBYK895FxzJjcWUPljh34xTISc2jXCatp0j6bWhyEWoFPrjRo9orfuG3GeC7Ha0Y1RpIA0RrS-IwJ_xxEb9JL7B-68p9blDxXwJWfDBMTz6WzontB11KkU8nIh_pFMp0vAQg7XJ4/s400/image-784761.png&quot; /&gt;&lt;/a&gt;  &lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFvvKqt7wFN6qiaAfMOIO4bsHB9e1qqjIQNrQav423NxADeH8Zwv7ssFeOGyZI_NaqHolclqCjYq4PVgXB69D8K8vlekCUF-3oCHM-KYUiP8B0ilX4CQW5CRHFHy6P3KdLCFFamJs6jOY/s1600/image-787769.png&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; id=&quot;BLOGGER_PHOTO_ID_6624742189566082594&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFvvKqt7wFN6qiaAfMOIO4bsHB9e1qqjIQNrQav423NxADeH8Zwv7ssFeOGyZI_NaqHolclqCjYq4PVgXB69D8K8vlekCUF-3oCHM-KYUiP8B0ilX4CQW5CRHFHy6P3KdLCFFamJs6jOY/s400/image-787769.png&quot; /&gt;&lt;/a&gt;   &lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cydye1069.blogspot.com/feeds/5564040488560792320/comments/default' title='發佈留言'/><link rel='replies' type='text/html' href='http://cydye1069.blogspot.com/2018/11/excel.html#comment-form' title='0 則留言'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5564040488560792320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6352798839577548669/posts/default/5564040488560792320'/><link rel='alternate' type='text/html' href='http://cydye1069.blogspot.com/2018/11/excel.html' title='Excel 教學：符合條件整列變色'/><author><name>戴忠淵</name><uri>http://www.blogger.com/profile/09824116877146354409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEjvRqBYK895FxzJjcWUPljh34xTISc2jXCatp0j6bWhyEWoFPrjRo9orfuG3GeC7Ha0Y1RpIA0RrS-IwJ_xxEb9JL7B-68p9blDxXwJWfDBMTz6WzontB11KkU8nIh_pFMp0vAQg7XJ4/s72-c/image-784761.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>