当前位置:网站首页>Monte Carlo py solves the area problem! (save pupils Series)
Monte Carlo py solves the area problem! (save pupils Series)
2022-04-23 20:20:00 【Install a sound 77】
Recently, I saw such a topic in my circle of friends , Once again refresh the difficulty of primary school students' question bank .
Excellent young bloggers are in front of excellent young bloggers , The curve problem of this ghost animal can naturally be easily solved by integral , But the title has already limited the level of grade 6 , How can you kill a chicken with an ox knife , Even smart as a blogger ,6 Don't talk about points when you're old ,cos Not at all ,( A female pupil said she could use tan,cos Angle solution ), Therefore, this is obviously too reluctant for the majority of primary school students to understand .
that , From the perspective of primary school students, is there any way to deal with this malicious problem ?
The answer is yes
As for the method , For those who are good at smashing cards Pupils throwing darts , Monte Carlo is obviously perfect for , About introducing and connecting a blog , Please read by yourself .
https://blog.csdn.net/binlin199012/article/details/80604080
First, we draw the outline of the figure , Just pick the part we need .
Then start throwing needles wildly
# Take the radius as 1 The circle of , Take the area calculation in the first quadrant as an example
import random
import math
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse, Circle
C=5000# cycles
s=0# Counter
# The field of view of the drawing
plt.xlim(xmax=4,xmin=0)
plt.ylim(ymax=4,ymin=0)
x1=np.arange(0, 4, 0.1)
y1=0.5*x1
plt.plot(x1, y1)
x2 = y2 = np.arange(0, 4, 0.1)
x2, y2 = np.meshgrid(x2,y2)
plt.contour(x2, y2, (x2-4)**2 + (y2-4)**2, [16]) #x**2 + y**2 = 9 Round
plt.show()
for i in range(C):
# Generate random coordinates (x,y)
x=4*random.random()# Generate 0-1 Random number between
#print(x)
y=4*random.random()# Generate 0-1 Random number between
#print(y)
y_predict=-math.sqrt(16-(x-4)**2) + 4
y_predict2=0.5*x
#print(y_predict)
if y_predict>=y and y_predict2>=y and x<=4:# Coordinates y Less than y_predict, It's a round point , That is to meet the conditions , Counter plus 1
s=s+1
plt.plot(x,y,'r+')
else:
plt.plot(x, y, 'b+')
plt.show()
predict_value=16*s/C
print(predict_value)
The injection result is shown in the figure
This is a vote 5000 Time , The calculation result is 1.23 about , Just an approximate solution .
But pupils can say to their teachers “ I can cast it indefinitely to approach the real solution !”
Of course, teachers don't like this “ Because what the computer produces is only pseudo-random , Can't get a real natural pointer ”
But smart pupils have long thought of a solution
“ The air resistance in Brownian motion is purely random , So I just stand high enough , You can get the real frequency by hand casting the pipeline ! ”
版权声明
本文为[Install a sound 77]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210551491499.html
边栏推荐
- 网络通信基础(局域网、广域网、IP地址、端口号、协议、封装、分用)
- DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
- SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
- PCL点云处理之计算两平面交线(五十一)
- STM32基础知识
- WordPress插件:WP-China-Yes解决国内访问官网慢的方法
- nc基础用法2
- Computing the intersection of two planes in PCL point cloud processing (51)
- Change the material of unity model as a whole
- DTMF dual tone multi frequency signal simulation demonstration system
猜你喜欢
[latex] 5 how to quickly write out the latex formula corresponding to the formula
考研英语唐叔的语法课笔记
Numpy - creation of data type and array
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
STM32 Basics
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
Tensorflow 2 basic operation dictionary
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
[graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
随机推荐
AQS learning
Vericrypt file hard disk encryption tutorial
Cadence Orcad Capture CIS更换元器件之Link Database 功能介绍图文教程及视频演示
R语言ggplot2可视化分面图(facet_wrap)、使用lineheight参数自定义设置分面图标签栏(灰色标签栏)的高度
MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte
R language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)
Grafana shares links with variable parameters
Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
网络通信基础(局域网、广域网、IP地址、端口号、协议、封装、分用)
NC basic usage 4
PCL点云处理之基于PCA的几何形状特征计算(五十二)
An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
Handwritten Google's first generation distributed computing framework MapReduce
Investigate why close is required after sqlsession is used in mybatties
After route link navigation, the sub page does not display the navigation style problem
R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of
NC basic usage 2
SIGIR'22「微软」CTR估计:利用上下文信息促进特征表征学习
PostgreSQL basic functions
Solution to PowerDesigner's failure to connect to MySQL in x64 system