-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx 14.py
More file actions
136 lines (91 loc) · 2.47 KB
/
Copy pathEx 14.py
File metadata and controls
136 lines (91 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# %%
print('___________ Ex 14 _______________ ')
import numpy as np
import matplotlib.pyplot as plt
'___________ Ex 14 _______(1)______ '
x=5
print('x=',x)
print ("Square Value of x : ", np.square(x))
print ("cube Value of x :", np.power(x,3))
print('\n')
teta=30
print('teta=',teta)
print ("sin (",teta,")=", np.sin(teta))
print ("cos of teta : ", np.cos(teta))
print ("radian of teta : ", np.radians(teta))
print('\n')
y=np.linspace(-1,1,500)
print('53 th =',y[53])
print('\n')
pi=np.pi
plt.plot(y,np.sin(2*np.pi*y))
plt.show()
'___________ Ex 14 _______(2)______ '
vec1 = np.array([ -1., 4., -9.])
mat1 = np.array([[ 1., 3., 5.], [7., -9., 2.], [4., 6., 8. ]])
vec2 = (np.pi/4)*vec1
print("vec2=",vec2)
vec2=np.cos(vec2)
print("vec2=",vec2)
vec3 =vec1+2*vec2
print("vec3=",vec3)
vec4=np.multiply(mat1,vec3)
print("vec4=",vec4)
vec5=np.matrix(mat1)*np.matrix(vec4)
print("vec5=",vec5)
print('mat1.transpose =',mat1.transpose())
print('det(mat1)=', np.linalg.det(mat1))
print('trace(mat1)=',np.trace(mat1))
print('min(vec1)=',np.min(vec1))
print('argmin(vec1)=',np.argmin(vec1))
print('min(mat1)=',np.min(mat1))
A=np.array([[17, 24, 1, 8, 15],
[23, 5, 7, 14, 16],
[ 4, 6, 13, 20, 22],
[10, 12, 19, 21, 3],
[11, 18, 25, 2, 9]])
print(np.sum(A,axis=0))
print(np.sum(A,axis=1))
if min(np.sum(A,axis=0))==max(np.sum(A,axis=0)) and min(np.sum(A,axis=1))==max(np.sum(A,axis=1)):
if np.sum(np.diag(A))==np.sum(np.fliplr(A)):
print('magic square')
else:
print('not a magic square')
else:
print('not a magic square')
np.random.rand(10, 10)
'___________ Ex 14 _______(3)______ '
x = np.linspace(0, 10, 50)
y1= np.exp(-x/10)*np.sin(np.pi*x)
y2 = x*np.exp(-x/3)
plt.plot(x,y1,x,y2,label = 'f(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()
phi=np.linspace(0,2*np.pi,400)
R=1.2
r=R+np.cos(phi)
x1=r*np.cos(phi)
y=r*np.sin(phi)
plt.plot(x1,y,'r')
plt.xlabel('mehvar x ha')
plt.ylabel('mehvar y ha')
plt.show()
r1 = 0.8 + np.cos(phi)
x1 = r1 * np.cos(phi)
y1 = r1 * np.sin(phi)
r2 = 1 + np.cos(phi)
x2 = r2 * np.cos(phi)
y2 = r2 * np.sin(phi)
r3 = 1.2 + np.cos(phi)
x3 = r3 * np.cos(phi)
y3 = r3 * np.sin(phi)
plt.subplot(3,1,1)
plt.plot(x1, y1, 'r')
plt.subplot(3,1,2)
plt.plot(x2, y2, 'r')
plt.subplot(3,1,3)
plt.plot(x3, y3, 'r')
plt.show()
# %%