当前位置:网站首页>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
边栏推荐
- An error is reported in the initialization metadata of the dolphin scheduler -- it turns out that there is a special symbol in the password. "$“
- Local call feign interface message 404
- [graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
- NC basic usage 4
- ArcGIS js api 4. X submergence analysis and water submergence analysis
- Vericrypt file hard disk encryption tutorial
- 【目标跟踪】基于帧差法结合卡尔曼滤波实现行人姿态识别附matlab代码
- Is the wechat CICC wealth high-end zone safe? How to open an account for securities
- CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
- 【PTA】L2-011 玩转二叉树
猜你喜欢
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Livego + ffmpeg + RTMP + flvjs to realize live video
Browser - learning notes
LeetCode动态规划训练营(1~5天)
[text classification cases] (4) RNN and LSTM film evaluation Tendency Classification, with tensorflow complete code attached
Computing the intersection of two planes in PCL point cloud processing (51)
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Grafana shares links with variable parameters
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
随机推荐
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
Mysql database and table building: the difference between utf8 and utf8mb4
Compact CUDA tutorial - CUDA driver API
nc基础用法
R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数和two_scatter函数可视化Cox回归的风险评分图、解读风险评分图、基于LIRI数据集(基因数据集)
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
中金财富公司怎么样,开户安全吗
redis 分布式锁
AQS learning
R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
DTMF双音多频信号仿真演示系统
PCL点云处理之基于PCA的几何形状特征计算(五十二)
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
[latex] 5 how to quickly write out the latex formula corresponding to the formula
PCA based geometric feature calculation of PCL point cloud processing (52)
使用 WPAD/PAC 和 JScript在win11中进行远程代码执行3
The second method of file upload in form form is implemented by fileitem class, servletfileupload class and diskfileitemfactory class.
Cadence Orcad Capture CIS更换元器件之Link Database 功能介绍图文教程及视频演示