A set of Julia examples.
Example 1: a simple julia code to estimate the value of pi by using Monte Carlo method.
output:
Number of points: 1.0e8
Value of the calculated π is: 3.14185516, Difference to the Julia Pi (%) -0.00835583855554624
4.595806 seconds (100.89 M allocations: 1.532 GiB, 1.45% gc time)
Example 2: a simple julia code to quickly calculate the sinus of angles close to zero between 0° and 1° by using a Taylor polynomial of degree seven: sin(x) = x - x3/3! + x5/5! - x7/7!
For a sample size greater than or equal to 1.e07, the computation time indicated by simplified sinus is approximately 38% less than that shown by the standard sinus function.
output:
Sample Size: 1.0e7
Simplified sinus:
0.394266 seconds (10.31 M allocations: 168.391 MiB, 4.23% gc time)
Strandard sinus:
0.631318 seconds (20.30 M allocations: 319.676 MiB, 1.06% gc time)
Max difference (%): 2.2204445221147957e-14
Example 3: a simple julia code to estimate the value of pi by using Monte Carlo method (Multithreading version).
How to Run:
./multithreading_pi.sh
output:
====ThreadID#2| π=3.14147| Error(%)=0.00382397
====ThreadID#1| π=3.14153| Error(%)=0.00203762
====ThreadID#6| π=3.14174| Error(%)=-0.0047513
====ThreadID#9| π=3.14145| Error(%)=0.00464521
====ThreadID#8| π=3.1415| Error(%)=0.00306385
====ThreadID#3| π=3.14146| Error(%)=0.00417029
====ThreadID#5| π=3.14149| Error(%)=0.00312242
====ThreadID#7| π=3.14151| Error(%)=0.00253927
====ThreadID#4| π=3.14175| Error(%)=-0.00515873
====ThreadID#10| π=3.14173| Error(%)=-0.00447373
===============================================
π=3.14156432 | Error(%)=0.0009018861742200533
8.877416 seconds (786.31 M allocations: 11.748 GiB, 33.06% gc time)
Example 4: a simple julia code to calculate factorial of a given number.
output:
44! = 2673996885588443136