#python-3.x #matrix
#python-3.x #матрица
Вопрос:
Я запускаю код на Python для построения графика момента и диаграммы сдвига, дающей силы, длину, величину силы, ограничения и местоположение. Когда я создаю матрицы, вместо 101 значения имеется только 51 значение, а остальные равны 0. Также первое значение для V должно быть .75. Длина равна 10 C1 равно 2 C2 равно 2 FL равно 2,5 FM равно 1 FN равно 1 Графики показывают, что значения также заканчиваются на 5.
FL=[0]
FM=[0]
n=0
Length = float(input("What is the length? In FT n"))
C1 = int(input("What is the left constraint?n 1 for Fixed. n 2 for Pinned n"))
C2 = int(input("What is the right constraint?n 1 for Fixed. n 2 for Pinned n"))
FN = int(input("How many forces are present? n"))
while (n<FN):
fl = float(input("What is the location of the force?n"))
FL.insert(n,fl)
fm = float(input("What is the magnitude of the force?n"))
FM.insert(n,fm)
n = n 1
#Code = str(input("What code is being used?n"))
from Forces import forces
forces=forces(Length, C1, C2, FL, FM, FN)
def forces(Length, C1, C2, FL, FM, FN):
#graph plottting
k=1
x=[0]
x1=0
while (k<101):
x1=k*Length/(100)
x.insert(k,x1)
k= k 1
import numpy as np
Mx=np.zeros(shape=(k,FN 1))
Vx=np.zeros(shape=(k,FN 1))
#NDS 2005
#Figure 7,8,9,10 amp; 11, Simple Beam - Concentrated load at Any point
if (C1==2 and C2==2):
NF=1
while (NF<=FN):
#moment diagram
np.put(Mx,(0,1),0, mode='clip')
m=1
m1=0
while(m<k-1):
if (float(FL[NF-1])< Length*(m/100)):
m1=m1-float(FM[NF-1])*float(FL[NF-1])/(100)
else:
m1=float(FM[NF-1])*(Length-float(FL[NF-1]))*m/(100)
np.put(Mx,(m,NF),m1,mode='clip')
m= m 1
np.put(Mx,(100,1),0,mode='clip')
#shear diagram points
v=0
v1=0
while(v<k):
if ((float(FL[NF-1])< Length*(v/100)) and v!=0):
v1=-float(FM[NF-1])*float(FL[NF-1])/(Length)
else:
v1=float(FM[NF-1])*(Length-float(FL[NF-1]))/(Length)
np.put(Vx,(v,NF),v1,mode='clip')
v= v 1
NF=NF 1
i=0
while (i<k):
NF=1
while (NF<=FN):
if (FN == 1):
Mx[i,0]=(Mx[i,NF])
Vx[i,0]=(Vx[i,NF])
else:
Mx[i,0]=(Mx[i,NF] Mx[i,0])
Vx[i,0]=(Vx[i,NF] Vx[i,0])
NF = NF 1
i=i 1
import matplotlib.pyplot as plt
plt.plot(x, Mx[:,0], color='g')
plt.xlabel('Length ft')
plt.ylabel('Kip ft')
plt.title('Moment Diagram')
plt.show()
import matplotlib.pyplot as plt
plt.plot(x, Vx[:,0], color='g')
plt.xlabel('Length ft')
plt.ylabel('Kip')
plt.title('Shear Diagram')
plt.show()
print (Mx)
print (Vx)
return();
actual
[[0. 0. ]
[0.225 0.225]
[0.375 0.375]
[0.525 0.525]
[0.675 0.675]
[0.825 0.825]
[0.975 0.975]
[1.125 1.125]
[1.275 1.275]
[1.425 1.425]
[1.575 1.575]
[1.725 1.725]
[1.875 1.875]
[1.825 1.825]
[1.775 1.775]
[1.725 1.725]
[1.675 1.675]
[1.625 1.625]
[1.575 1.575]
[1.525 1.525]
[1.475 1.475]
[1.425 1.425]
[1.375 1.375]
[1.325 1.325]
[1.275 1.275]
[1.225 1.225]
[1.175 1.175]
[1.125 1.125]
[1.075 1.075]
[1.025 1.025]
[0.975 0.975]
[0.925 0.925]
[0.875 0.875]
[0.825 0.825]
[0.775 0.775]
[0.725 0.725]
[0.675 0.675]
[0.625 0.625]
[0.575 0.575]
[0.525 0.525]
[0.475 0.475]
[0.425 0.425]
[0.375 0.375]
[0.325 0.325]
[0.275 0.275]
[0.225 0.225]
[0.175 0.175]
[0.125 0.125]
[0.075 0.075]
[0.025 0.025]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0. ]
[0. 0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 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]
[ 0. 0. ]]
Ответ №1:
Замените все функции put на =
Например: замените np.put(Mx,(0,1),0, mode=’clip’) на Mx[0,1]=0