import numpy as np
import pylab

n = int(raw_input("Enter the number of nodes in the beam: "))
noelem = n - 1
K = np.zeros([n, n])
F = np.zeros([n, 1])

EI = float(raw_input("Enter the bending stiffness of the beam(Ncm^2): "))
L = float(raw_input("Enter the length of the beam(cm): "))
M = float(raw_input("Enter the internal bending moment(Ncm): "))

lenelem = L/noelem
elestif = EI/lenelem
elestif1 = -elestif
elefor = -(M * lenelem) / 2
for element in range(n - 1):
    K[element, element] += elestif
    K[element + 1, element + 1] += elestif
    K[element, element + 1] += elestif1
    K[element + 1, element] += elestif1
    F[element, 0] += elefor
    F[element + 1, 0] += elefor

nodalsol = np.zeros([n, 1])
nodalsol[0] = float(raw_input("Enter the displacement value at node1: "))
nodalsol[noelem] = float(raw_input("Enter the displacement value at node" + str(n) + ": "))

numiter = 10
soleqn = range(1, noelem)

for iteration in range(numiter):
    for row in soleqn:
        const = F[row]
        for col in range(n):
            if row != col:
                const = const - (K[row, col] * nodalsol[col])
        nodalsol[row] = const/K[row, row]

xlen = [0]
for length in range(1, n):
    xlen.append(length * lenelem)

ylen = []
for values in range(n):
    ylen.append(nodalsol[values, 0])

pylab.plot(xlen, ylen,)
pylab.title('Simply Supported Beam Subjected to Concentrated End Momemts')
pylab.xlabel('Length of Beam (cm)')
pylab.ylabel('Beam Deflection (cm)')
pylab.grid(True)
pylab.show()

9ec8fe12aaf151705eaed6ce13b2f1e250bdf2c1
<mask token>

<mask token>
for element in range(n - 1):
    K[element, element] += elestif
    K[element + 1, element + 1] += elestif
    K[element, element + 1] += elestif1
    K[element + 1, element] += elestif1
    F[element, 0] += elefor
    F[element + 1, 0] += elefor
<mask token>
for iteration in range(numiter):
    for row in soleqn:
        const = F[row]
        for col in range(n):
            if row != col:
                const = const - K[row, col] * nodalsol[col]
        nodalsol[row] = const / K[row, row]
<mask token>
for length in range(1, n):
    xlen.append(length * lenelem)
<mask token>
for values in range(n):
    ylen.append(nodalsol[values, 0])
pylab.plot(xlen, ylen)
pylab.title('Simply Supported Beam Subjected to Concentrated End Momemts')
pylab.xlabel('Length of Beam (cm)')
pylab.ylabel('Beam Deflection (cm)')
pylab.grid(True)
pylab.show()

<mask token>
n = int(raw_input('Enter the number of nodes in the beam: '))
noelem = n - 1
K = np.zeros([n, n])
F = np.zeros([n, 1])
EI = float(raw_input('Enter the bending stiffness of the beam(Ncm^2): '))
L = float(raw_input('Enter the length of the beam(cm): '))
M = float(raw_input('Enter the internal bending moment(Ncm): '))
lenelem = L / noelem
elestif = EI / lenelem
elestif1 = -elestif
elefor = -(M * lenelem) / 2
for element in range(n - 1):
    K[element, element] += elestif
    K[element + 1, element + 1] += elestif
    K[element, element + 1] += elestif1
    K[element + 1, element] += elestif1
    F[element, 0] += elefor
    F[element + 1, 0] += elefor
nodalsol = np.zeros([n, 1])
nodalsol[0] = float(raw_input('Enter the displacement value at node1: '))
nodalsol[noelem] = float(raw_input('Enter the displacement value at node' +
    str(n) + ': '))
numiter = 10
soleqn = range(1, noelem)
for iteration in range(numiter):
    for row in soleqn:
        const = F[row]
        for col in range(n):
            if row != col:
                const = const - K[row, col] * nodalsol[col]
        nodalsol[row] = const / K[row, row]
xlen = [0]
for length in range(1, n):
    xlen.append(length * lenelem)
ylen = []
for values in range(n):
    ylen.append(nodalsol[values, 0])
pylab.plot(xlen, ylen)
pylab.title('Simply Supported Beam Subjected to Concentrated End Momemts')
pylab.xlabel('Length of Beam (cm)')
pylab.ylabel('Beam Deflection (cm)')
pylab.grid(True)
pylab.show()

import numpy as np
import pylab
n = int(raw_input('Enter the number of nodes in the beam: '))
noelem = n - 1
K = np.zeros([n, n])
F = np.zeros([n, 1])
EI = float(raw_input('Enter the bending stiffness of the beam(Ncm^2): '))
L = float(raw_input('Enter the length of the beam(cm): '))
M = float(raw_input('Enter the internal bending moment(Ncm): '))
lenelem = L / noelem
elestif = EI / lenelem
elestif1 = -elestif
elefor = -(M * lenelem) / 2
for element in range(n - 1):
    K[element, element] += elestif
    K[element + 1, element + 1] += elestif
    K[element, element + 1] += elestif1
    K[element + 1, element] += elestif1
    F[element, 0] += elefor
    F[element + 1, 0] += elefor
nodalsol = np.zeros([n, 1])
nodalsol[0] = float(raw_input('Enter the displacement value at node1: '))
nodalsol[noelem] = float(raw_input('Enter the displacement value at node' +
    str(n) + ': '))
numiter = 10
soleqn = range(1, noelem)
for iteration in range(numiter):
    for row in soleqn:
        const = F[row]
        for col in range(n):
            if row != col:
                const = const - K[row, col] * nodalsol[col]
        nodalsol[row] = const / K[row, row]
xlen = [0]
for length in range(1, n):
    xlen.append(length * lenelem)
ylen = []
for values in range(n):
    ylen.append(nodalsol[values, 0])
pylab.plot(xlen, ylen)
pylab.title('Simply Supported Beam Subjected to Concentrated End Momemts')
pylab.xlabel('Length of Beam (cm)')
pylab.ylabel('Beam Deflection (cm)')
pylab.grid(True)
pylab.show()

import numpy as np
import pylab

n = int(raw_input("Enter the number of nodes in the beam: "))
noelem = n - 1
K = np.zeros([n, n])
F = np.zeros([n, 1])

EI = float(raw_input("Enter the bending stiffness of the beam(Ncm^2): "))
L = float(raw_input("Enter the length of the beam(cm): "))
M = float(raw_input("Enter the internal bending moment(Ncm): "))

lenelem = L/noelem
elestif = EI/lenelem
elestif1 = -elestif
elefor = -(M * lenelem) / 2
for element in range(n - 1):
    K[element, element] += elestif
    K[element + 1, element + 1] += elestif
    K[element, element + 1] += elestif1
    K[element + 1, element] += elestif1
    F[element, 0] += elefor
    F[element + 1, 0] += elefor

nodalsol = np.zeros([n, 1])
nodalsol[0] = float(raw_input("Enter the displacement value at node1: "))
nodalsol[noelem] = float(raw_input("Enter the displacement value at node" + str(n) + ": "))

numiter = 10
soleqn = range(1, noelem)

for iteration in range(numiter):
    for row in soleqn:
        const = F[row]
        for col in range(n):
            if row != col:
                const = const - (K[row, col] * nodalsol[col])
        nodalsol[row] = const/K[row, row]

xlen = [0]
for length in range(1, n):
    xlen.append(length * lenelem)

ylen = []
for values in range(n):
    ylen.append(nodalsol[values, 0])

pylab.plot(xlen, ylen,)
pylab.title('Simply Supported Beam Subjected to Concentrated End Momemts')
pylab.xlabel('Length of Beam (cm)')
pylab.ylabel('Beam Deflection (cm)')
pylab.grid(True)
pylab.show()
