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 a = ML/(E*I) eq = sp.Eq( y.diff(z,1) + a * y*y , 0 ) yrez = sp.dsolve(eq) print(yrez) yrez2 = sp.dsolve(eq, ics={y.subs(z,0):y0}) print(yrez2) results.append(yrez.subs(z, 190)) df = pd.DataFrame(results).T df.to_excel(writer)
上記のコードを実行すると,以下のエラーが出てしまいます.
Excelからデータを読み込むこと,方程式を解くことを切り離して行うと,どちらともうまく回ります.方程式だけを解くときはy0に適当に値を入れました.
どのように改良すればよいでしょうか?
エラー文
0 3 0 0.0000000058 0.25 Eq(y(z), -1/(C1 + 0.152757414958076*z)) Traceback (most recent call last): File "C:\Users\片持ち.py", line 56, in <module> yrez2 = sp.dsolve(eq, ics={y.subs(z,0):y0}) 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 210, in _desolve n=terms, x0=x0, prep=prep) File "C:\Users\Python\Python37\site-packages\sympy\solvers\ode\ode.py", line 963, in classify_ode ics = sympify(ics) File "C:\Users\Python\Python37\site-packages\sympy\core\sympify.py", line 361, in sympify return conv(a) File "C:\Users\Python\Python37\site-packages\sympy\core\containers.py", line 310, in <lambda> converter[dict] = lambda d: Dict(*d.items()) File "C:\Users\Python\Python37\site-packages\sympy\core\containers.py", line 234, in __new__ elements = frozenset(items) File "C:\Users\Python\Python37\site-packages\sympy\core\containers.py", line 106, in __hash__ return hash(self.args) TypeError: unhashable type: 'DataFrame' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\片持ち.py", line 62, 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
Excelの入力ファイルの中身がみたいです。
あなたの回答
tips
プレビュー