113數A選擇17

模考考完自己驗證答案

Mon Jul 22 2024
291 words · 2 minutes

image

  • 其中in_R
def in_R(x, y):
return (x >= abs(x-y) and y >= abs(x-y) and 1-x >= abs(x-y) and 1-y >= abs(x-y))

(x, y) 是否在區域 R 內。四個條件:

  1. x >= abs(x-y): 確保點到左邊界的距離不小於 |x-y|
  2. y >= abs(x-y): 確保點到下邊界的距離不小於 |x-y|
  3. 1-x >= abs(x-y): 確保點到右邊界的距離不小於 |x-y|
  4. 1-y >= abs(x-y): 確保點到上邊界的距離不小於 |x-y|

具體來說:

  • 如果 x < |x-y|,那麼菱形的左頂點會超出正方形的左邊界。
  • 如果 y < |x-y|,那麼菱形的下頂點會超出正方形的下邊界。
  • 如果 1-x < |x-y|,那麼菱形的右頂點會超出正方形的右邊界。
  • 如果 1-y < |x-y|,那麼菱形的上頂點會超出正方形的上邊界。

只有當這四個條件都滿足時,(x, y) 才被認為在R 內。


用python畫出來

import numpy as np
import matplotlib.pyplot as plt
def in_R(x, y):return (x >= abs(x-y) and y >= abs(x-y) and 1-x >= abs(x-y) and 1-y >= abs(x-y))
x = np.linspace(0, 1, 500)
y = np.linspace(0, 1, 500)
X, Y = np.meshgrid(x, y)
R = np.frompyfunc(in_R, 2, 1)(X, Y).astype(np.float64)
plt.figure(figsize=(10, 10))
plt.imshow(R, extent=[0, 1, 0, 1],origin='lower',cmap='Blues')
plt.xlabel('x')
plt.ylabel('y')
plt.grid(True)
plt.show()
  • 標點後 722

(1322)2+(2313)2×12+12×12=13\sqrt{(\frac{1}{3}-\frac{2}{2})^2+(\frac{2}{3}-\frac{1}{3})^2} \times \sqrt{1^2+1^2} \times \frac{1}{2} = \frac{1}{3}


Thanks for reading!

113數A選擇17

Mon Jul 22 2024
291 words · 2 minutes