session=StartExternalSession["Julia"] test = "function testpi(size) sample = rand(size, 2) dist = broadcast(hypot, sample[:,1], sample[:,2]) return sample, dist end"; pitest=ExternalEvaluate[session,test] size=100000 data=pitest[size]; ListPlot[GatherBy[Transpose[data[[1]]],Norm[#]<1&],Frame ->True,AspectRatio -> 1] Length@GatherBy[Transpose[data[[1]]], Norm[#]<1&][[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[->] (-1.2,0)--(1.1,0) node[right]{$x$}; \draw[->] (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<1,"blue!90","red!90")} \fill[\col] (\x,\y) circle (0.1pt) ; } \end{tikzpicture} \end{document}
Mathematica 教學:Call Julia from Mathematica
由 戴忠淵 於 Monday, February 20, 2023
10:41 PM 發表
讀者回應 ( 0 意見 )
訂閱Post Comments (Atom)
Post a Comment
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~