0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

できませんでした。不等式であらわされた領域「2024 公立千歳科学技術大学 前期【1】(7)」をChatGPTとsympyでやってみたい。

Last updated at Posted at 2024-06-16

・???集合の意味cupと表示について勉強中。
 ソースコードは、ページ後半です。

0.png

オリジナル

・数学入試問題 様

・大学入試数学問題集成 様>【1】(7)テキスト

オリジナル様の方法で

・勉強中? 私はあきらめました。

ChatGPT-3.5先生へ

大学入試数学問題集成 様> 【1】(7)テキスト

・ページのソースを表示です。MathMLです。
 省略しようと思いましたが、大学入試数学問題集成 様 の全文から必要部分の抜粋です。

<div class="qbody">
<p class="slevel"><a name="q-0107" 
id="q-0107"></a><span 
class="qnum">【1】</span> 以下の問いに答えなさい.解答欄には答えのみ書きなさい.</p>
<p class="s1level"><a name="s-0107" id="s-0107"></a><span 
class="shomon1">(7)</span> <math>
<mrow><mi>x</mi><mo>&ic;</mo><mi>y</mi></mrow><mspace width=".2em"></mspace>
</math>平面において,<math>
<mrow><mi mathvariant="normal">A</mi><mo>=</mo><mo stretchy="false">(</mo>
<mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo>
<mo lspace=".2em" rspace=".2em">|</mo><msup><mi>x</mi><mn>2</mn></msup>
<mo>+</mo><msup><mi>y</mi><mn>2</mn></msup><mo>&lE;</mo><mn>1</mn>
<mo rspace=".2em" stretchy="false">}</mo><mtext>,</mtext></mrow>
</math><math>
<mrow><mi mathvariant="normal">B</mi><mo>=</mo><mo stretchy="false">{</mo>
<mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo>
<mo lspace=".2em" rspace=".2em">|</mo><mo stretchy="false">(</mo><mi>x</mi>
<mo>+</mo><mi>y</mi><mo stretchy="false">)</mo><mo>&it;</mo><mo stretchy="false">(</mo>
<mn>2</mn><mo>&it;</mo><mi>x</mi><mo>-</mo><mn>2</mn><mo>&it;</mo>
<mi>y</mi><mo>+</mo><msqrt><mn>3</mn></msqrt><mo>-</mo><mn>1</mn>
<mo stretchy="false">)</mo><mo>&lt;</mo><mn>0</mn><mo rspace=".2em" stretchy="false">}</mo></mrow>
</math>とする.<math>
<mover><mrow><mover><mi mathvariant="normal">A</mi><mo>&OverBar;</mo></mover>
<mo>&cup;</mo><mi mathvariant="normal">B</mi></mrow><mo>&OverBar;</mo></mover>
<mspace width=".2em"></mspace>
</math>が表す領域の面積を求めなさい.
</p>
</div>
</div>

??? Final Answer

日本語で。
数値積分で
import numpy as np
from scipy.integrate import dblquad

# 円の内部で領域Bの条件を満たす部分の積分範囲を設定
def integrand(x, y):
    return 1

# 領域Bの条件
def condition_B(x, y):
    return (x + y) * (2*x - 2*y + np.sqrt(3) - 1) < 0

# 積分範囲の設定
x_lower = -1
x_upper = 1

# yの範囲を決定するための関数
def y_lower(x):
    return -np.sqrt(1 - x**2)

def y_upper(x):
    return np.sqrt(1 - x**2)

# 条件を満たす部分だけ積分するための関数
def integrand_conditioned(y, x):
    if condition_B(x, y):
        return 1
    else:
        return 0

# 数値積分の実行
area, error = dblquad(integrand_conditioned, x_lower, x_upper, y_lower, y_upper)

print(f"領域の面積: {area}, 誤差: {error}")
sympyで。厳密値で。
import sympy as sp

# 変数の定義
x, y = sp.symbols('x y')

# 円の方程式と直線の方程式
circle_eq = x**2 + y**2 - 1
line1_eq = x + y
line2_eq = 2*x - 2*y + sp.sqrt(3) - 1

# 領域Bの条件
region_B_condition = sp.And((line1_eq < 0) & (line2_eq > 0) | (line1_eq > 0) & (line2_eq < 0))

# 領域Aの条件
region_A_condition = circle_eq <= 0

# 領域Aと領域Bの和集合の条件
union_condition = sp.And(region_A_condition, region_B_condition)

# 領域Aと領域Bの和集合の面積を計算
area = sp.integrate(sp.integrate(sp.Piecewise((1, union_condition), (0, True)), (y, -sp.sqrt(1-x**2), sp.sqrt(1-x**2))), (x, -1, 1))

# 結果を表示
# sp.pprint(area)

print("#",sp.pprint(area))
# None
sympyとmatplotlibを使って作図したいので、ソースコードをお願いします。
import sympy as sp
import matplotlib.pyplot as plt
import numpy as np

# 変数の定義
x, y = sp.symbols('x y')

# 円の方程式と直線の方程式
circle_eq = x**2 + y**2 - 1
line1_eq = x + y
line2_eq = 2*x - 2*y + sp.sqrt(3) - 1

# 領域Bの条件
region_B_condition = sp.And((line1_eq < 0) & (line2_eq > 0) | (line1_eq > 0) & (line2_eq < 0))

# 領域Aの条件
region_A_condition = circle_eq <= 0

# 領域Aと領域Bの和集合の条件
union_condition = sp.And(region_A_condition, region_B_condition)

# 領域Aと領域Bの和集合の面積を計算
area = sp.integrate(sp.integrate(sp.Piecewise((1, union_condition), (0, True)), (y, -sp.sqrt(1-x**2), sp.sqrt(1-x**2))), (x, -1, 1))

# 結果を表示
print("領域の面積: ", area)

# 作図
fig, ax = plt.subplots()

# 円をプロット
circle = plt.Circle((0, 0), 1, color='blue', alpha=0.3)
ax.add_artist(circle)

# 直線をプロット
x_vals = np.linspace(-1.5, 1.5, 400)
y_vals1 = -x_vals
y_vals2 = (2*x_vals + sp.sqrt(3) - 1) / 2

ax.plot(x_vals, y_vals1, 'r', label='x + y = 0')
ax.plot(x_vals, y_vals2, 'g', label='2x - 2y + sqrt(3) - 1 = 0')

# グラフの範囲とラベル設定
ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.set_aspect('equal', adjustable='box')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.title('領域 $\\overline{A} \\cup \\overline{B}$ の視覚化')

# グリッド表示
plt.grid(True)

# 作図の表示
plt.show()

・私は、ここまでです。
・作図結果はページの最初です。

いつもの? sympyの実行環境と 参考のおすすめです。

(テンプレート)

いつもと違うおすすめです。

>MathMLの cup は他ページにあります。全部で4箇所

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?