2021-civ-73-part-2 python
2021-civ-73-part-2 python
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56
58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55
57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
15 30 45 60 75 90 105 120 135 150 165 180 195 210 225 240 255 270 285 300 315
330 345 360 375 390 405 420 435 450 465 480 495 510 525 540 555 570 585 600 615
630 645 660 675 690 705 720 735 750 765 780 795 810 825 840 855 870 885 900 915
930 945 960 975 990
1 4 9 16 25 36 49 64 81 100
1 8 27 64
1
[9]: #Printing Prime No.s from 1 to 100
for i in range (1,101):
x = 0
for j in range (1,101):
if i%j == 0:
x = x+1
if x == 2:
print (i,end=' ')
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
if x == 2:
print ('Entered No. is a Prime No.')
else:
print ('Entered No. is Not a Prime No.')
Enter a No: 4
Entered No. is Not a Prime No.
usingg sign: [5 7 9]
using function: [5 7 9]
2
print ('tan: ', z3)
[[1 2]
[3 4]]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[47], line 4
2 import numpy as np
3 x = np.array([[1,2],[3,4]])
----> 4 y = np.flaten(x)
5 print(y)
3
AttributeError: module 'numpy' has no attribute 'flaten'
[[1 4 7]
[2 5 8]
[3 6 9]]
[[ 3.15251974e+15 -6.30503948e+15 3.15251974e+15]
[-6.30503948e+15 1.26100790e+16 -6.30503948e+15]
[ 3.15251974e+15 -6.30503948e+15 3.15251974e+15]]
-9.51619735392994e-16
[[ 28]
[ 64]
[100]]
[[-0.46666667]
[ 0.93333333]
[ 0.2 ]]
19
4
[4]: #Array slicing
#lower limit will be included
print (x[1:])
[ 8 9 10 20]
[7 8]
[ 8 9 10]
5
[2 5]
[[2 3]
[5 6]]
(2, 3)
[[1 2 3 4 5 6]]
[[1 2]
[3 4]
[5 6]]
[[ 1 2 10 20]
[ 3 4 30 40]]
5
[7]: #Array joining on bottom (v for vertically)
import numpy as np
x = np.array([[1,2],[3,4]])
y = np.array([[10,20],[30,40]])
z2 = np.vstack((x,y))
print (z2)
[[ 1 2]
[ 3 4]
[10 20]
[30 40]]
[23]: #Matplotlib.pyplot
# Matplotlib is the plotting library for python and numpy
# Pyplot is a module of matplotlib that provides MATLAB like interface
# plot a graph for x = [1,2,3,4], y = [1,4,9,16]
import numpy as np
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,4,9,16],'ro')
6
[25]: plt.plot([1,2,3,4],[1,4,9,16],'r-')
[28]: plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.show()
plt.plot([1,2,3,4],[1,4,9,16],'b-')
7
[28]: [<matplotlib.lines.Line2D at 0x16307159370>]
8
[29]: plt.plot([1,2,3,4],[1,4,9,16],'ro')
plt.plot([1,2,3,4],[1,4,9,16],'b-')
9
[30]: plt.plot([1,2,2,1,1],[1,1,4,4,1],'g-')
10
[56]: #Functions used to space intervals
# Linspace
# x = np.linspace(3,18,6)
# 3 is lower limit, 18 is upper limit, 6 equally spaced No.s
# Space = (UL-LL)/(6-1)
x = np.linspace (3,27,7)
print (x)
[37]: #Arrange
import numpy as np
x = np.arange(0,12,2)
print (x)
x = np.arange(5,20,3)
print (x)
[ 0 2 4 6 8 10]
[ 5 8 11 14 17]
11
x = np.array([1,2,3,4])
y = np.zeros_like (x)
print (y)
[0 0 0 0]
12
[57]: #plot a graph of quadratic Eq.
x = np.arange(0,360+0.1,0.1)
pi = 3.1415
y = np.sin(x*pi/180)
plt.plot(y,'ro')
plt.plot(y,'g-')
plt.title('Sin Curve')
plt.xlabel('@')
plt.ylabel('y')
plt.grid(True)
[64]: #Make a SFD of beam having length 6m, Point load = 2KN at center (a=3)
import numpy as np
import matplotlib.pyplot as plt
L = 6
p = 2
a = 3
x = np.arange(0,L+0.001,0.001)
#zeros like is used to have a variable shape as that of x so that we can stores␣
↪value answer in y
13
y = np.zeros_like(x)
z = np.zeros_like(x)
for i in range (len(x)):
if x[i]==0:
y[i]=0
elif x[i]< a:
y[i] = P/2
elif x[i] >= a and x[i]<L:
y[i] = p/2 - p
elif x[i] ==L:
y[i] = 0
for i in range (len(x)):
z[i] = 0
plt.plot(x,y,'g-')
plt.plot(x,z,'b--')
[68]: #Make a BMD of beam having length 6m, Point load = 2KN at center (a=3)
import numpy as np
import matplotlib.pyplot as plt
L = 6
14
p = 2
a = 3
x = np.arange(0,L+0.001,0.001)
#zeros like is used to have a variable shape as that of x so that we can stores␣
↪value answer in y
y = np.zeros_like(x)
z = np.zeros_like(x)
for i in range (len(x)):
if x[i]==0:
y[i]=0
elif x[i] <= a:
y[i] = (P/2)*x[i]
elif x[i] > a:
y[i] = (p/2)*x[i] - p*(x[i]-a)
elif x[i] ==L:
y[i] = 0
for i in range (len(x)):
z[i] = 0
plt.plot(x,y,'g-')
plt.plot(x,z,'b--')
15
[ ]: #SFD & BMD for UDL on simply supported beam
#User input the Load and location and we draw SFD& BMD
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
16
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
17
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
18
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
19