import sympy as sp import math import cv2 import numpy as np import matplotlib.pyplot as plt import csv import os import glob import pandas as pd in_excel_file = 'matome' file = in_excel_file pd.options.display.precision = 10 options = {} options['strings_to_formulas'] = False options['strings_to_urls'] = False with pd.ExcelWriter('yre_z_DH=0.4_.xlsx', mode='w') as writer: results = [] for i in range(35): print(i) def loadyre(file,i): yre = pd.read_excel(file+'.xlsx', skiprows=4, usecols=[i+3], nrows=5, header=None) #解析対象となるデータの読み込み return yre y0 = loadyre(file,i) print(y0) D = 0.016 H = 0.04 d = 0.015 h = 0.039 U = i*0.25 + 0.25 print(U) π = math.pi m = 0.0156 L = 0.3 fc = 9.0 ρ = 1.18 M = (m/(ρ*H*D*L))*(D/H) Vr = U/(fc*H) A = H*L sp.init_printing() sp.var('z') y = sp.Function('y')(z) #yはzの関数(Function) E = 4.28*10*10*10*10*10*10 I = (1/12)*(D*H*H*H-d*h*h*h) dCL = 0.3 #dCL/dα FL = -((ρ*U*A)/2*M)*dCL ML = FL/2 eq = sp.Eq( sp.diff(y, z ,2)+(ML/(E*I))*(y^2)*sp.diff(y, z, 1), 0 ) yrez = sp.dsolve(eq) yrez2 = sp.dsolve(eq, ics={y.diff(z,1).subs(z,0):0}) yrez3 = sp.dsolve(eq, ics={y.subs(z,0):y0, y.diff(z,1).subs(z,0):0}) print(yrez) print(yrez2) print(yrez3) results.append(yrez.subs(z, 190)) df = pd.DataFrame(results).T df.to_excel(writer)
上記にプログラミングを組んだのですが,Cannot solveと出ているので計算結果ができないようです.
どのようにしたら改善するでしょうか?
エラー
0 3 0 0.0000000058 0.25 Traceback (most recent call last): File "C:\Users\片持ち.py", line 53, in <module> yrez = sp.dsolve(eq) File "C:\Users\Python\Python37\site-packages\sympy\solvers\ode\ode.py", line 631, in dsolve x0=x0, n=n, **kwargs) File "C:\Users\Python\Python37\site-packages\sympy\solvers\deutils.py", line 241, in _desolve raise NotImplementedError(dummy + "solve" + ": Cannot solve " + str(eq)) NotImplementedError: solve: Cannot solve -0.152757414958076*y(z)**2*Derivative(y(z), z) + Derivative(y(z), (z, 2)) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\片持ち.py", line 63, in <module> df.to_excel(writer) File "C:\Users\Python\Python37\site-packages\pandas\io\excel\_base.py", line 1020, in __exit__ self.close() File "C:\Users\Python\Python37\site-packages\pandas\io\excel\_base.py", line 1024, in close content = self.save() File "C:\Users\Python\Python37\site-packages\pandas\io\excel\_openpyxl.py", line 80, in save self.book.save(self.handles.handle) File "C:\Users\Python\Python37\site-packages\openpyxl\workbook\workbook.py", line 407, in save save_workbook(self, filename) File "C:\Users\Python\Python37\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook writer.save() File "C:\Users\Python\Python37\site-packages\openpyxl\writer\excel.py", line 275, in save self.write_data() File "C:\Users\Python\Python37\site-packages\openpyxl\writer\excel.py", line 89, in write_data archive.writestr(ARC_WORKBOOK, writer.write()) File "C:\Users\Python\Python37\site-packages\openpyxl\workbook\_writer.py", line 148, in write self.write_views() File "C:\Users\Python\Python37\site-packages\openpyxl\workbook\_writer.py", line 135, in write_views active = get_active_sheet(self.wb) File "C:\Users\Python\Python37\site-packages\openpyxl\workbook\_writer.py", line 33, in get_active_sheet raise IndexError("At least one sheet must be visible") IndexError: At least one sheet must be visible
追記
手計算で解く手法を記載します。
初期値とかは適当なので、上記プログラムとは一致してません。
d²y/dx²+ay²dy/dx=0
dy/dx=pとおくと
d²y/dx²
=dp/dx
=pdp/dy
pdp/dy+ay²p=0
p(dp/dy+ay²)=0
p=0のときy=C (Cは任意定数)
p≠0のとき
dp/dy+ay²=0
p=-(a/3)y³+A
その式(eq)は手計算で解ける式なのでしょうか?
解けます!
手計算だと以下のようになります。
d²y/dx²+ay²dy/dx=0
dy/dx=pとおくと
d²y/dx²
=dp/dx
=pdp/dy
pdp/dy+ay²p=0
p(dp/dy+ay²)=0
p=0のときy=C (Cは任意定数)
p≠0のとき
dp/dy+ay²=0
p=-(a/3)y³+A
「(y**2)」を除くとsympyで解けるようなので式が複雑なことによるNotImplementedErrorでしょうか。Wolfram Alphaですとそのままでも解けるようですが「標準の計算時間制限を超えました...」のメッセージが出たのでやはり複雑な式かもしれません。
あなたの回答
tips
プレビュー