Created
November 26, 2022 04:22
-
-
Save junpeitsuji/d21e6b608fad60fd2e87d2e8d406bb39 to your computer and use it in GitHub Desktop.
関の発微算法の問14の数値解を計算するPythonスクリプト。(参考: # https://www.youtube.com/watch?v=cHaVY-h22Dk) ただし、この動画は問題の条件と途中式に誤植があるので注意(本プログラムは誤植修正済み)。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 関の発微算法の問14の数値解を計算するPythonスクリプト | |
# 参考: | |
# https://www.youtube.com/watch?v=cHaVY-h22Dk | |
# ただし、この動画は問題の条件と途中式に誤植があるので注意(本プログラムは誤植修正済み) | |
from scipy.optimize import fsolve | |
import numpy as np | |
# 最小化したい関数 | |
def f(p): | |
x = p[0] | |
y = p[1] | |
z = p[2] | |
u = p[3] | |
v = p[4] | |
w = p[5] | |
P = x**4 * u**2 + y**2 * z**2 * u**2 + x**2 * u**4 - x**2 * y**2 * u**2 - x**2 * z**2 * u**2 + (y**4 + x**2 * z**2 - x**2 * u**2 - y**2 * u**2 - x**2 * y**2 - y**2 * z**2) * v**2 + y**2 * v**4 | |
Q = x**2 * y**2 + z**4 - x**2 * u**2 - z**2 * u**2 - x**2 * z**2 - y**2 * z**2 + (u**2 - z**2 - y**2) * v**2 | |
R = z**2 | |
return [x**3 - y**3 - 271, y**3 - z**3 - 217, z**3 - u**3 - 60.8, \ | |
u**3 - v**3 - 326.2, v**3 - w**3 - 61, | |
P + Q * w**2 + R * w**4] | |
# 初期値 | |
x0 = np.array([10, 9, 8, 7.6, 5, 4]) | |
# 準最適解を求める | |
sol = fsolve(f, x0, xtol=1.0E-12) | |
print(f'x = {sol[0]}') | |
print(f'y = {sol[1]}') | |
print(f'z = {sol[2]}') | |
print(f'u = {sol[3]}') | |
print(f'v = {sol[4]}') | |
print(f'w = {sol[5]}') | |
print("") | |
# 確認 | |
print(f'x^3 - y^3 = {sol[0]**3 - sol[1]**3}') | |
print(f'y^3 - z^3 = {sol[1]**3 - sol[2]**3}') | |
print(f'z^3 - u^3 = {sol[2]**3 - sol[3]**3}') | |
print(f'u^3 - v^3 = {sol[3]**3 - sol[4]**3}') | |
print(f'v^3 - w^3 = {sol[4]**3 - sol[5]**3}') | |
print(f'(幾何的な条件から得られる式) = {f(sol)[5]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment