TroglodyteDerivations
commited on
Commit
•
789f285
1
Parent(s):
4cdb8c0
Updated lines 9 & 10 with the converting of v1 and v2 into numpy arrays. Also, the Object behavior / Method vector_add with self.v1 + self.v2 (line 17). And the underlying Object behavior / Method plot_vector_add with numpy array removal in declarations, echoing functionality deriving from numpy array declarations in lines 9 & 10
Browse files
app.py
CHANGED
@@ -4,24 +4,24 @@ import matplotlib.pyplot as plt
|
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
|
7 |
-
class
|
8 |
def __init__(self, v1, v2):
|
9 |
-
self.v1 = v1
|
10 |
-
self.v2 = v2
|
11 |
|
12 |
def problem_add(self):
|
13 |
problem_add_prompt = print(f'What does vector 1: {self.v1} + vector 2: {self.v2} equal?')
|
14 |
return problem_add_prompt
|
15 |
|
16 |
def vector_add(self):
|
17 |
-
v3 = print(f'The new vector 3 produced = vector 1: {self.v1} + vector 2: {self.v2} =',
|
18 |
return v3
|
19 |
|
20 |
def plot_vector_add(self):
|
21 |
plt.figure(figsize=(10,5))
|
22 |
-
plt.plot([0,
|
23 |
-
plt.plot([0,
|
24 |
-
plt.plot([0,
|
25 |
plt.xlabel('X')
|
26 |
plt.ylabel('Y')
|
27 |
plt.title('Vector Addition')
|
@@ -36,7 +36,7 @@ class Vector_Addition:
|
|
36 |
return image
|
37 |
|
38 |
def vector_addition(v1, v2):
|
39 |
-
vector_addition =
|
40 |
v3 = vector_addition.vector_add()
|
41 |
plot = vector_addition.plot_vector_add()
|
42 |
return v3, plot
|
|
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
|
7 |
+
class Vector_Addition_Subtraction:
|
8 |
def __init__(self, v1, v2):
|
9 |
+
self.v1 = np.array(v1)
|
10 |
+
self.v2 = np.array(v2)
|
11 |
|
12 |
def problem_add(self):
|
13 |
problem_add_prompt = print(f'What does vector 1: {self.v1} + vector 2: {self.v2} equal?')
|
14 |
return problem_add_prompt
|
15 |
|
16 |
def vector_add(self):
|
17 |
+
v3 = print(f'The new vector 3 produced = vector 1: {self.v1} + vector 2: {self.v2} =', self.v1+self.v2)
|
18 |
return v3
|
19 |
|
20 |
def plot_vector_add(self):
|
21 |
plt.figure(figsize=(10,5))
|
22 |
+
plt.plot([0, self.v1[0]], [0, self.v1[1]], 'b', label='v1')
|
23 |
+
plt.plot([0, self.v2[0]+self.v1[0]], [0, self.v2[1]+self.v1[1]], 'r', label='v2')
|
24 |
+
plt.plot([0, self.v1[0]+ self.v2[0]], [0, self.v1[1]+ self.v2[1]], 'k', label='v1+v2')
|
25 |
plt.xlabel('X')
|
26 |
plt.ylabel('Y')
|
27 |
plt.title('Vector Addition')
|
|
|
36 |
return image
|
37 |
|
38 |
def vector_addition(v1, v2):
|
39 |
+
vector_addition = Vector_Addition_Subtraction(v1, v2)
|
40 |
v3 = vector_addition.vector_add()
|
41 |
plot = vector_addition.plot_vector_add()
|
42 |
return v3, plot
|