पायथन - एक फ़ंक्शन को एकीकृत करना और परिणामों की साजिश रचना
मैं बर्नौली के बीम समीकरण को संख्यात्मक रूप से हल करने और परिणामों की साजिश रचने की कोशिश कर रहा हूं। समीकरण का पहला व्युत्पन्न ढलान है और दूसरा व्युत्पन्न विक्षेपण है। मैंने चरण-दर-चरण समस्या का सामना किया, पहले फ़ंक्शन को प्लॉट किया और फिर इसे एकीकृत किया और एक ही आरेख पर एकीकरण परिणामों की साजिश रची।
मेरा अब तक का कोड बेलो है। मुझे संदेह है कि समस्या इस तथ्य में निहित है कि Integrated.quad एक एकल मान लौटाता है और मैं इससे कई मान प्राप्त करने का प्रयास कर रहा हूं। क्या किसी को पता है कि यह कैसे दृष्टिकोण है?
from scipy import integrate
import numpy as np
from pylab import *
# Beam parameters
L = 100
w = 10
h = 10
I = (w*h**3)/12
E = 200000
F = 100
def d2y_dx2(x):
return (-F*x)/(E*I)
a = 0.0
b = L
res, err = integrate.quad(d2y_dx2, a, b)
t = np.linspace(a,b,100)
ax = subplot(111)
ax.plot(t, d2y_dx2(t))
ax.plot(t, res(t))
show()
EDIT: बेलो को विल्क्रैक के उत्तर के साथ संशोधित कोड दिया गया है। यह कोड अब काम करता है, लेकिन परिणाम सही नहीं हैं। नीचे मैंने बीम समीकरण के विश्लेषणात्मक समाधानों का उपयोग करके परिणामों को साजिश करने के लिए कोड जोड़ा जो सही हैं।
from scipy import integrate
import numpy as np
import matplotlib.pyplot as plt
# Beam parameters
L = 100
w = 10
h = 10
I = (w*h**3)/12
E = 200000
F = 100
# Integration parameters
a = 0.0
b = L
# Define the beam equation
def d2y_dx2(x,y=None):
return (-F*x)/(E*I)
def something(x):
return integrate.quad(d2y_dx2)[0]
# Define the integration1 - slope
def slope(t):
slope_res = []
for x in t:
res1, err = integrate.quad(d2y_dx2, a, b)
slope_res.append(res1)
return slope_res
# Define the integration1 - deflection
def defl(t1):
defl_res = []
for t in t1:
res2, err = integrate.dblquad(d2y_dx2,a,b, lambda x: a, lambda x: b)
defl_res.append(res2)
return defl_res
# Plot
fig, (ax1, ax2, ax3) = plt.subplots(3)
t = np.linspace(a,b,100)
t1 = np.linspace(a,b,100)
ax1.plot(t, d2y_dx2(t))
ax2.plot(t, slope(t))
ax3.plot(t1, defl(t1))
plt.show()
विश्लेषणात्मक समाधान, कोड और परिणाम bellow। विक्षेपित बीम का आकार चारों ओर घुमाया जाता है, बीम का अंत x = 0 पर होता है।
from __future__ import division #to enable normal floating division
import numpy as np
import matplotlib.pyplot as plt
# Beam parameters
w = 10 #beam cross sec width (mm)
h = 10 #beam cross sec height (mm)
I = (w*h**3)/12 #cross sec moment of inertia (mm^4)
I1 = (w*h**3)/12
E = 200000 #steel elast modul (N/mm^2)
L = 100 #beam length(mm)
F = 100 #force (N)
# Define equations
def d2y_dx2(x):
return (-F*x)/(E*I)
def dy_dx(x):
return (1/(E*I))*(-0.5*F*x**2 + 0.5*F*L**2)
def y(x):
return (1/(E*I))*(-(1/6)*F*(x**3) + (1/2)*F*(L**2)*x - (1/3)*F*(L**3))
# Plot
fig, (ax1, ax2, ax3) = plt.subplots(3)
a = 0
b = L
x = np.linspace(a,b,100)
ax1.plot(x, d2y_dx2(x))
ax2.plot(x, dy_dx(x))
ax3.plot(x, y(x))
plt.show()

जवाब
शायद आप कुछ इस तरह की कोशिश कर सकते हैं
from scipy import integrate
import numpy as np
import matplotlib.pyplot as plt
# Beam parameters
L = 100
w = 10
h = 10
I = (w*h**3)/12
E = 200000
F = 100
# Integration parameters
a = 0.0
b = L
# Define the beam equation
def d2y_dx2(x,y=None):
return (-F*x)/(E*I)
def something(x):
return integrate.quad(d2y_dx2)[0]
# Define the integration1 - slope
def slope(t):
slope_res = []
for x in t:
res1, err = integrate.quad(d2y_dx2, a, b)
slope_res.append(res1)
return slope_res
# Define the integration1 - deflection
def defl(t1):
defl_res = []
for t in t1:
res2, err = integrate.dblquad(d2y_dx2,a,b, lambda x: a, lambda x: b)
defl_res.append(res2)
return defl_res
# Plot
fig, (ax1, ax2, ax3) = plt.subplots(3)
t = np.linspace(a,b,100)
t1 = np.linspace(a,b,100)
ax1.plot(t, d2y_dx2(t))
ax2.plot(t, slope(t))
ax3.plot(t1, defl(t1))
plt.show()
परिणाम:

मुझे लगता है कि मुझे ढलान का हल मिल गया। मैं बाद में एक कोशिश करूँगा। यहाँ अद्यतन है।
from scipy import integrate
import numpy as np
import matplotlib.pyplot as plt
# Beam parameters
L = 100
w = 10
h = 10
I = (w*h**3)/12
E = 200000
F = 100
# Integration parameters
a = 0.0
b = L
# Define the beam equation
def d2y_dx2(x,y=None):
return (-F*x)/(E*I)
# Define the integration1 - slope
def slope(x):
slope_res = np.zeros_like(x)
for i,val in enumerate(x):
y,err = integrate.quad(f,a,val)
slope_res[i]=y
return slope_res
# Define the integration1 - deflection
def defl(x):
defl_res = np.zeros_like(x)
for i,val in enumerate(x):
y, err = integrate.dblquad(d2y_dx2,0,val, lambda x: 0, lambda x: val)
defl_res[i]=y
return defl_res
# Plot
fig, (ax1, ax2, ax3) = plt.subplots(3)
t = np.linspace(a,b,100)
t1 = np.linspace(a,b,100)
ax1.plot(t, d2y_dx2(t))
ax2.plot(t, slope(t))
ax3.plot(t1, defl(t1))
plt.show()
नया परिणाम:

अभी भी पिछले एक से संघर्ष कर रहा है ...