sympyで不静定はりを解く(片持ち梁編)

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

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

# 参考資料

片持ち梁の曲げモーメントとせん断力（集中荷重） 

http://omm.ishikawa-nct.ac.jp/ex/exercises/no-kgAAA/#answer

片持ち梁の曲げモーメントとせん断力（等分布荷重）

http://omm.ishikawa-nct.ac.jp/ex/exercises/iHjdgAAA/#answer

# WolframAlpha
#### 片持ち梁（集中荷重）

http://www.wolframalpha.com/input/?i=%7Bv''(x)%3DP*l%2FB,v(l)%3D0,v'(l)%3D0%7D

　　(出力)v(x) = (l P (l - x)^2)/(2 B)
　

https://www.wolframalpha.com/input/?i=%5B%7Bv''(x)%3DP*l%2FB,v(l)%3D0,v'(l)%3D0%7D+,+x%3D0%5D

　　(出力)v(0) = (l^3 P)/(2 B)

#### 片持ち梁（等分布荷重）

http://www.wolframalpha.com/input/?i=%7Bv''(x)%3D-w*x%5E2%2F2%2FB,v(l)%3D0,v'(l)%3D0%7D

(出力)v''(x) = -(w x^2)/(2 B)

http://www.wolframalpha.com/input/?i=%5B%7Bv''(x)%3D-w*x%5E2%2F2%2FB,v(l)%3D0,v'(l)%3D0%7D,x%3D0%5D

(出力)v(0) = -(l^4 w)/(8 B)
# 自乗の表示が間違っています。sympy
#### 片持ち梁（集中荷重）(元ﾈﾀ)より

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

    l = symbols('l', positive=True, real=True)
    RA = symbols('R_A')
    MA = symbols('M_A')
    VA = symbols('V_A')
    P = symbols('P')
    E, I = symbols('E, I')
    x = symbols('x')
    loads = [
        (-RA,l, -1),
        (P,  0, -1),
        (MA, l, -2),
    ]

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

    b.solve_for_reaction_loads(RA,  MA)
    print(b.reaction_loads)
    print("v(x)=",b.deflection())
    print("v(0)=",b.deflection().subs({x: 0}))

    # こことんでもなく雑な数字
    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: P, M_A: -P*l}
```
v(x)= (P*l**3/3 - P*l**2*x/2 - P*l*SingularityFunction(x, l, 2)/2 + P*SingularityFunction(x, 0, 3)/6 - P*SingularityFunction(x, l, 3)/6)/(E*I)
v(0)= P*l**3/(3*E*I)
```
#### 片持ち梁（等分布荷重）(元ﾈﾀ)より

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

    l = symbols('l', positive=True, real=True)
    RA = symbols('R_A')
    MA = symbols('M_A')
    VA = symbols('V_A')
    w = symbols('w')
    E, I = symbols('E, I')
    x = symbols('x')
    loads = [
        (-RA,l, -1),
        (-w,  0,  0, l),
        (MA, l, -2),
    ]

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

    b.solve_for_reaction_loads(RA,  MA)
    print(b.reaction_loads)
    print("v(x)=",b.deflection())
    print("v(0)=",b.deflection().subs({x: 0}))

    # こことんでもなく雑な数字
    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, M_A: l**2*w/2}
v(x)= (-l**4*w/8 + l**3*w*x/6 + l**2*w*SingularityFunction(x, l, 2)/4 + l*w*SingularityFunction(x, l, 3)/6 - w*SingularityFunction(x, 0, 4)/24 + w*SingularityFunction(x, l, 4)/24)/(E*I)
v(0)= -l**4*w/(8*E*I)
```
# 勉強中