漫谈圆周率π值的计算论文 下载本文

南京师范大学泰州学院本科毕业论文

hold on

tx = [0 -0.018887578 -0.010905291 0.015474116 -0.008608213 0.015441920 -0.008111011 0.020641880 0.025117259 0.010984385 0.005345186 0.000068280 0.005363236 0.007086468 0.001270498 0.002728617 0.000591920 -0.000105111 0.000485732]; stem(d,tx,'o')

title('图3-20 利用随机整数互素计算误差随取数数量增加模拟值的变化图') xlabel('取数数量')

ylabel('误差值')

legend('参考线','实验模拟值')

set(gca,'XTicklabel',['00 '; '200 ';'400 ';'600 ';'800 ';'1000 ';'3000 ';'5000 ';'20000';'40000']) %axis([0 18 3.08 3.22])

************************************************************************************************************************************************************** 附录3-12

使用软件Matlab7.0

d = 0:18;

h1 = line([0 18],[3.141592653589793 3.141592653589793]) get(h1)

set(h1, 'LineWidth', 2.5)

hold on

tx1 = [0 3.110000000 3.153000000 3.162666667 3.126500000 3.129600000 3.129333333 3.123142857 3.136500000 3.139555556 3.142200000 3.132400000 3.147733333 3.148500000 3.147320000 3.143120000 3.141130000 3.141246667 3.142050000];

plot(d,tx1,'-.dr')

tx2 = [0 3.093535650 3.106235555 3.200680525 3.207464022 3.168438472 3.184616969 3.116460497 3.147967361 3.131756008 3.182246374 3.163304771 3.117298460 3.124282505 3.124265889 3.126721964 3.143516503 3.135204343 3.138897469]; plot(d,tx2,':*')

tx3 = [0 3.122705076 3.130687363 3.157066770 3.132984441 3.157034574 3.133481643 3.162234534 3.166709913 3.152577039 3.146937839 3.141660933 3.146955890 3.148679122 3.142863151 3.144321271 3.142184573 3.141487543 3.142078386]; plot(d,tx3,'o',d,tx3)

title('图3-21 MoteCarlo法三种方式模拟结果的比较图') xlabel('投点数量')

ylabel('模拟值')

legend('圆周率值',' 单位圆投点法','蒲丰投针法','随机整数互素法')

set(gca,'XTicklabel',['00 '; '200 ';'400 ';'600 ';'800 ';'1000 ';'3000 ';'5000 ';'20000';'40000']) axis([0 18 3.08 3.22])

******************************************************************************* d = 0:18;

h1 = line([0 18],[0 0]) get(h1)

set(h1, 'LineWidth', 0.5) hold on

40

南京师范大学泰州学院本科毕业论文

tx1 = [0 -0.031592654 0.011407346 0.021074013 -0.015092654 -0.011992654 -0.012259320 -0.018449796 -0.005092654 -0.002037098 0.000607346 -0.00919265 0.006140680 0.006907346 0.005727346 0.001527346 -0.000462654 -0.000345987 0.000457346];

stem(d,tx1,'--d')

tx2 = [0 -0.048057003 -0.035357099 0.059087872 0.065871369 0.026845819 0.043024316 -0.025132156 0.006374708 -0.009836646 0.040653720 0.021712117 -0.024294194 -0.017310149 -0.017326765 -0.014870689 0.001923849 -0.006388311 -0.002695185]; stem(d,tx2,'*')

tx3 = [0 -0.018887578 -0.010905291 0.015474116 -0.008608213 0.015441920 -0.008111011 0.020641880 0.025117259 0.010984385 0.005345186 0.000068280 0.005363236 0.007086468 0.001270498 0.002728617 0.000591920 -0.000105111 0.000485732]; stem(d,tx3,'o')

title('图3-22 MoteCarlo法三种方式模拟误差的比较图') xlabel('投点数量')

ylabel('误差值')

legend('参考线',' 单位圆投点法','蒲丰投针法','随机整数互素法')

set(gca,'XTicklabel',['00 '; '200 ';'400 ';'600 ';'800 ';'1000 ';'3000 ';'5000 ';'20000';'40000']) %axis([0 18 3.1 3.17])

41