sympyで不静定はりを解く(両端固定梁編)

オリジナル
sympyで不静定はりを解く

~~https://qiita.com/tehen_/items/78de14be5de482d84a26 ~~

# 参考資料




# WolframAlpha
勉強中
#### 両端固定梁（中心荷重）
#### 両端固定梁（等分布荷重）
# 自乗の表示が間違っています。sympy
#### 両端固定梁（中心荷重）---------------エラーがでます。教えて下さい。?????????????????????????
```PartialScript.py
def _main():
    from sympy.core import symbols
    from sympy.plotting import plot

    l = symbols('l', positive=True, real=True)
    RA, RB = symbols('R_A, R_B')
    MA, MB = symbols('M_A, M_B')
    P = symbols('P')
    E, I = symbols('E, I')
    x = symbols('x')
    loads = [
        (-RA, 0, -1),
        (-RB, l, -1),
        (P, 0.5*l, -1),
        (MA, 0, -2),
        (MB, l, -2)
    ]

    b = Beam(l, E, I)
    for load in loads:
        b.apply_load(*load)
    b.bc_deflection = [
        (0, 0),
        (l, 0)
    ]
    b.bc_slope = [
        (0, 0),
        (l, 0)
    ]

    b.solve_for_reaction_loads(RA, RB, MA, MB)
    print(b.reaction_loads)
    print("v(x)=",b.deflection())
    #print("v(l/2)=",b.deflection().subs({x: 0.5*l}))


    # こことんでもなく雑な数字
    constants = {l: 1, P: 1, E: 1, I: 1}
    plot(
        # b.shear_force().subs(constants),
        b.bending_moment().subs(constants),
        # b.slope().subs(constants),
        # b.deflection().subs(constants),
        (b.variable, 0, b.length.subs(constants))
    )

if __name__ == '__main__':
    _main()

#{R_A: 0.5*P, R_B: 0.5*P, M_A: 0.125*P*l, M_B: -0.125*P*l}
#Traceback (most recent call last):
#  File "C:/Users/xxx/.PyCharmCE2018.1/config/scratches/scratch_4.py", line 87, in <module>
#    _main()
#  File "C:/Users/xxx/.PyCharmCE2018.1/config/scratches/scratch_4.py", line 73, in _main
#    print("v(x)=",b.deflection())
#  File "C:\Users\xxx\PycharmProjects\untitled4\venv\lib\site-packages\sympy\physics\continuum_mechanics\beam.py", line 511, in deflection
#    deflection_curve = integrate((E*I)*self.slope(), x) + C4
#  File "C:\Users\xxx\PycharmProjects\untitled4\venv\lib\site-packages\sympy\physics\continuum_mechanics\beam.py", line 455, in slope
#    slope_curve = slope_curve.subs({C3: constants[0][0]})
#IndexError: list index out of range

```

#### 両端固定梁（等分布荷重）---------------1/384と表示する方法を教えて下さい。????????????????

```PartialScript.py
def _main():
    from sympy.core import symbols
    from sympy.plotting import plot

    l = symbols('l', positive=True, real=True)
    RA, RB = symbols('R_A, R_B')
    MA, MB = symbols('M_A, M_B')
    P = symbols('P')
    E, I = symbols('E, I')
    x = symbols('x')
    w = symbols('w')
    loads = [
        (-RA, 0, -1),
        (-w, 0, 0, l),
        (-RB, l, -1),
        (MA, 0, -2),
        (MB, l, -2)
    ]

    b = Beam(l, E, I)
    for load in loads:
        b.apply_load(*load)
    b.bc_deflection = [
        (0, 0),
        (l, 0)
    ]
    b.bc_slope = [
        (0, 0),
        (l, 0)
    ]

    b.solve_for_reaction_loads(RA, RB, MA, MB)
    print(b.reaction_loads)
    print("v(x)=",b.deflection())
    print("v(l/2)=",b.deflection().subs({x: 0.5*l}))
    print(' 1/384=',-1/384)

    # こことんでもなく雑な数字
    constants = {l: 1, w: 1, E: 1, I: 1}
    plot(
        # b.shear_force().subs(constants),
        b.bending_moment().subs(constants),
        # b.slope().subs(constants),
        # b.deflection().subs(constants),
        (b.variable, 0, b.length.subs(constants))
    )

if __name__ == '__main__':
    _main()

#{R_A: -l*w/2, R_B: -l*w/2, M_A: -l**2*w/12, M_B: l**2*w/12}
#v(x)= (-l**2*w*SingularityFunction(x, 0, 2)/24 + l**2*w*SingularityFunction(x, l, 2)/24 + l*w*SingularityFunction(x, 0, 3)/12 + l*w*SingularityFunction(x, l, 3)/12 - w*SingularityFunction(x, 0, 4)/24 + w*SingularityFunction(x, l, 4)/24)/(E*I)
#v(l/2)= -0.00260416666666667*l**4*w/(E*I)
# 1/384= -0.0026041666666666665
```