Coin is heads with probability 1/3 and tails with probability 2/3. The expectation of independent flips until first heads is _____.
时间: 2024-05-25 16:13:29 浏览: 213
The expected number of flips until the first heads is given by the formula:
E(X) = 1/p
where p is the probability of getting heads on any given flip.
In this case, the probability of getting heads on any given flip is 1/3. Therefore, the expected number of flips until the first heads is:
E(X) = 1/(1/3) = 3
So the answer is 3.
相关问题
You could also create code to simulate the Monty Hall problem. 1. Create a function named random_door, which uses numpy.random.choice to sample 1 door randomly from a list of integer door indices (1-3 in this case). Use this function to randomly select the door the car is behind and the contestant’s initial choice of doors. 2. Create a function monty_choice, which chooses the door Monty opens, conditional on the contestant’s choice of doors and the door with the car. For the case where the contestant has selected the door with the car, select the door to open by simulating the flip of a fair coin using the np.random.binomial function with n = 1. 3. Create a function win_car, which determines if the contestant wins the car, conditional on the strategy selected, {switch, noswitch}, the door the contestant selected, the door with the car, and the door Monty opened. 4. Create a function named simulation that allows you to run the simulation n = 1000 times, with a switch or noswitch strategy. 5. Execute your simulation for each possible strategy. For the two strategies, plot side by side bar charts showing the numbers of successes and failures for each strategy. 6. Describe the strategy a contestant should adopt for this game. How much will the chosen strategy change the probability of winning a car? Is this result consistent with the conditional probability of this problem?
Sure, here's a Python implementation of the Monty Hall problem:
```python
import numpy as np
import matplotlib.pyplot as plt
def random_door():
# sample 1 door randomly from 3 doors
return np.random.choice([1, 2, 3])
def monty_choice(contestant_choice, car_door):
# Monty chooses a door to open conditional on the contestant's choice and the car's location
if contestant_choice == car_door:
# if the contestant has selected the door with the car, flip a fair coin to choose which door Monty opens
return np.random.binomial(1, 0.5) + 1
else:
# otherwise, open the door that is not selected by the contestant or the one with the car
return list(set([1, 2, 3]) - set([contestant_choice, car_door]))[0]
def win_car(strategy, contestant_choice, car_door, monty_choice):
# determine if the contestant wins the car, conditional on the strategy, the contestant's choice, the car's location, and Monty's choice
if strategy == "switch":
# if the contestant switches doors, select the other unopened door
new_choice = list(set([1, 2, 3]) - set([contestant_choice, monty_choice]))[0]
return new_choice == car_door
else:
# otherwise, stick with the original choice
return contestant_choice == car_door
def simulation(n, strategy):
# run the simulation n times with the given strategy
car_door = random_door()
contestant_choice = random_door()
successes = 0
failures = 0
for i in range(n):
monty = monty_choice(contestant_choice, car_door)
if win_car(strategy, contestant_choice, car_door, monty):
successes += 1
else:
failures += 1
return successes, failures
# run the simulation for each strategy
n = 1000
switch_successes, switch_failures = simulation(n, "switch")
no_switch_successes, no_switch_failures = simulation(n, "noswitch")
# plot the results
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].bar(["Success", "Failure"], [switch_successes, switch_failures])
axes[0].set_title("Switch Strategy")
axes[1].bar(["Success", "Failure"], [no_switch_successes, no_switch_failures])
axes[1].set_title("No Switch Strategy")
plt.show()
```
In this implementation, the `random_door()` function randomly selects a door for the car and the contestant's initial choice. The `monty_choice()` function chooses the door for Monty to open, given the contestant's choice and the car's location. The `win_car()` function determines whether the contestant wins the car, given the strategy, the contestant's choice, the car's location, and Monty's choice. Finally, the `simulation()` function runs the simulation `n` times with a given strategy and returns the number of successes and failures.
According to the simulation results, the contestant should switch doors to maximize their chances of winning the car. The switch strategy has a success rate of around 66.5%, while the no switch strategy has a success rate of around 33.5%. This result is consistent with the conditional probability of the problem, which shows that the probability of winning the car increases from 1/3 to 2/3 if the contestant switches doors.
翻译This SiO2 shell is a key component in the mechanism for reversible actuation, as illustrated by finite element analysis (FEA) in Fig. 1C. An increase in temperature transforms the SMA (nitinol) from the martensitic to the austenitic phase, causing the 3D structure to flatten into a 2D shape. The responses of the SMA elements at the joints act as driving forces to deform the PI skeleton. This process also elastically deforms the SiO2 shell, resulting in a counter force that limits the magnitude of the deformation. The change in shape ceases when the forces from the shell balance those from the joints (right frame in Fig. 1C). Upon a reduction in temperature, the SMA changes from the austenitic back to the martensitic phase, thereby reducing the force produced by the SMA at the joints to zero. The elastic forces associated with the shell then push the entire system back to the original 3D geometry (left frame in Fig. 1C). Figure S3A simulates the moments generated by the SMA and the SiO2 shell. In the FEA model, the SiO2 shell appears on both the outer and inner surfaces of the 3D robot, consistent with experiments (fig. S3B). Although a single layer of the SiO2 shell at the outer or inner surface can also provide restoring force, the double-layer shell structure follows naturally from the conformal deposition process. This actuation scheme allows for reversible shape transformations using a one-way shape memory material. Without the shell, the structure only supports a single change in shape, from 3D to 2D, as illustrated in fig. S3C. Figure 1D shows optical images of a freestanding 3D peekytoe crab on the edge of a coin, highlighting the preserved 3D geometry enabled by the SiO2 shell after release from the elastomer substrate. Other 3D structures in geometries that resemble baskets, circular helices, and double-floor helices also exhibit high shape storage ratios (>85%) after cycles of heating and cooling (fig. S4). This ratio (s) is defined as s = 1 − |L1 − L0|/L0 × 100%, where L0 and L1 are the distances between the bonding sites at both ends at the initial stage and subsequent stages, respectively
这个SiO2壳是可逆作用机制的关键组成部分,如图1C所示的有限元分析所示。温度的升高将SMA(尼钛)从马氏体相转变为奥氏体相,导致3D结构变成2D形状。连接处SMA元件的响应作为变形PI骨架的驱动力。这个过程也会弹性变形SiO2壳,产生抵消变形幅度的对抗力。当壳体受力平衡连接处的力时,形状的变化停止(图1C右侧)。温度降低时,SMA从奥氏体相变回马氏体相,因此连接处由SMA产生的力减少到零。与壳体相关的弹性力将整个系统推回原始的3D几何形状(图1C左侧)。图S3A模拟了SMA和SiO2壳体产生的力矩。在有限元分析模型中,SiO2壳体出现在3D机器人的外表面和内表面,与实验结果一致(图S3B)。虽然在外表面或内表面只有一个SiO2壳层也可以提供恢复力,但双层壳体结构自然地遵循共形沉积过程。这种作用机制使用单向形状记忆材料实现可逆形状转换。没有壳体,结构只支持从3D到2D的单次形状变化,如图S3C所示。图1D显示了一只自由站立的3D Peekytoe蟹在硬币边缘的光学图像,突出了SiO2壳在从弹性体基底释放后保留的3D几何形状。几何形状类似于篮子、圆螺旋和双层螺旋的其他3D结构在加热和冷却循环后也表现出高形状存储比率(>85%)(图S4)。这个比率(εs)定义为εs = 1-|L1-L0|/L0×100%,其中L0和L1分别是初始阶段和随后阶段两端结合点之间的距离。
阅读全文