-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a4fd2cd
Showing
578 changed files
with
205,388 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
def cofactor(matrix, omit_row, omit_column): | ||
row = len(matrix) | ||
column = len(matrix[0]) | ||
return [[matrix[row][column] for column in range(column) if column != omit_column] | ||
for row in range(row) if row != omit_row] | ||
|
||
|
||
def cofactor_determinant(matrix, omit_row, omit_column): | ||
matrix = cofactor(matrix, omit_row, omit_column) | ||
return determinant(matrix) | ||
|
||
|
||
def determinant(matrix): | ||
dimensions = len(matrix) | ||
if dimensions == 2: | ||
det = matrix[0][0] * matrix[1][1] - matrix[1][0] * matrix[0][1] | ||
return det | ||
else: | ||
det = 0 | ||
for i in range(dimensions): | ||
constant = matrix[0][i] | ||
if i % 2 == 1: | ||
constant = constant * -1 | ||
det += constant * cofactor_determinant(matrix, 0, i) | ||
return det | ||
|
||
|
||
def transpose(matrix): | ||
row = len(matrix) | ||
column = len(matrix[0]) | ||
transpose_matrix = [[matrix[row][column] for row in range(row)] for column in range(column)] | ||
return transpose_matrix | ||
|
||
|
||
def inverse(matrix): | ||
if determinant(matrix) != 0: | ||
dimensions = len(matrix) | ||
det = determinant(matrix) | ||
cofactor_matrix = [] | ||
for i in range(dimensions): | ||
cofactor_row = [] | ||
for j in range(dimensions): | ||
constant = -1 if (i % 2) ^ (j % 2) else 1 | ||
cofactor_row.append(constant * cofactor_determinant(matrix, i, j)) | ||
cofactor_matrix.append(cofactor_row) | ||
|
||
comatrix = transpose(cofactor_matrix) | ||
inverse_matrix = [[component / det for component in row] for row in comatrix] | ||
return inverse_matrix | ||
else: | ||
print("This matrix does not have an inverse") | ||
|
||
|
||
def scalar_multiply(matrix, scalar): | ||
scaled_matrix = [[component * scalar for component in row] for row in matrix] | ||
return scaled_matrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import math | ||
|
||
|
||
def norm(vector): | ||
sum_squares = 0 | ||
for component in vector: | ||
sum_squares += component * component | ||
norm_value = math.sqrt(sum_squares) | ||
return norm_value | ||
|
||
|
||
def unit(vector): | ||
length = norm(vector) | ||
unit_vector = [component / length for component in vector] | ||
return unit_vector | ||
|
||
|
||
def scalar_multiply(vector, scalar): | ||
scaled_vector = [component * scalar for component in vector] | ||
return scaled_vector | ||
|
||
|
||
def add(vector, vector2): | ||
sum_vector = [i + j for i, j in zip(vector, vector2)] | ||
return sum_vector | ||
|
||
|
||
def subtract(vector, vector2): | ||
difference_vector = [i - j for i, j in zip(vector, vector2)] | ||
return difference_vector | ||
|
||
|
||
def dot(vector, vector2): | ||
dot_product = 0 | ||
for i, j in zip(vector, vector2): | ||
dot_product += i*j | ||
return dot_product | ||
|
||
|
||
def angle(vector, vector2): | ||
norm1 = norm(vector) | ||
norm2 = norm(vector2) | ||
dot_product = dot(vector, vector2) | ||
vector_angle = math.acos(dot_product / (norm1 * norm2)) | ||
return vector_angle | ||
|
||
|
||
def cross_product(vector, vector2): | ||
det1 = (vector[1] * vector2[2]) - (vector2[1] * vector[2]) | ||
det2 = (vector[0] * vector2[2]) - (vector2[0] * vector[2]) | ||
det3 = (vector[0] * vector2[1]) - (vector2[0] * vector2[1]) | ||
cross = "(" + str(det1) + ")i + (" + str(-det2) + ")j + (" + str(det3) + ")k" | ||
return cross |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import MatrixOperations | ||
import VectorOperations | ||
choice = input(""" | ||
This is a Vector and Matrices Calculator. Select from the following: | ||
1) Vector Calculator | ||
2) Matrices Calculator | ||
""") | ||
if choice == "1": | ||
vector_selection = input(""" | ||
Selection Menu: | ||
1) Norm | ||
2) Unit Vector | ||
3) Scalar Multiplication | ||
4) Addition | ||
5) Subtraction | ||
6) Dot Product | ||
7) Angle | ||
8) Cross Product (Only for 3D vectors) | ||
""") | ||
size = int(input("Enter the size of the vector:")) | ||
vector = [int(input("Enter Value for Vector 1: ")) for i in range(size)] | ||
|
||
if vector_selection == "1": | ||
norm = VectorOperations.norm(vector) | ||
print("Norm: ", norm) | ||
if vector_selection == "2": | ||
unit_vector = VectorOperations.unit(vector) | ||
print(unit_vector) | ||
if vector_selection == "3": | ||
scalar = float(input("Please input scale factor: ")) | ||
scaled_vector = VectorOperations.scalar_multiply(vector, scalar) | ||
print(scaled_vector) | ||
if vector_selection == "4": | ||
vector2 = [int(input("Enter Value for Vector 2: ")) for i in range(size)] | ||
vector_sum = VectorOperations.add(vector, vector2) | ||
print(vector_sum) | ||
if vector_selection == "5": | ||
vector2 = [int(input("Enter Values of Subtrahend Vector: ")) for i in range(size)] | ||
vector_difference = VectorOperations.subtract(vector, vector2) | ||
print(vector_difference) | ||
if vector_selection == "6": | ||
vector2 = [int(input("Enter Values for Vector 2: ")) for i in range(size)] | ||
dot_product = VectorOperations.dot(vector, vector2) | ||
print("Dot Product: ", dot_product) | ||
if vector_selection == "7": | ||
vector2 = [int(input("Enter Values for Vector 2: ")) for i in range(size)] | ||
vector_angle = VectorOperations.angle(vector, vector2) | ||
print("Angle: ", round(vector_angle, 2), " radians") | ||
if vector_selection == "8": | ||
vector2 = [int(input("Enter Values for Vector 2: ")) for i in range(size)] | ||
cross = VectorOperations.cross_product(vector, vector2) | ||
print(cross) | ||
elif choice == "2": | ||
matrix_selection = input(""" | ||
Selection Menu: | ||
1) Determinant | ||
2) Transpose | ||
3) Inverse | ||
4) Scalar Multiplication | ||
""") | ||
dimensions = int(input("Enter the dimensions of the SQUARE matrix:")) | ||
matrix = [[int(input("Enter Value: ")) for i in range(dimensions)] for j in range(dimensions)] | ||
|
||
if matrix_selection == "1": | ||
determinant = MatrixOperations.determinant(matrix) | ||
print("Determinant: ", determinant) | ||
elif matrix_selection == "2": | ||
transpose = MatrixOperations.transpose(matrix) | ||
print(transpose) | ||
elif matrix_selection == "3": | ||
inverse = MatrixOperations.inverse(matrix) | ||
print(inverse) | ||
elif matrix_selection == "4": | ||
scalar = float(input("Please input the scalar:")) | ||
scaled_matrix = MatrixOperations.scalar_multiply(matrix, scalar) | ||
print(scaled_matrix) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import sys | ||
import os | ||
import re | ||
import importlib | ||
import warnings | ||
|
||
|
||
is_pypy = '__pypy__' in sys.builtin_module_names | ||
|
||
|
||
warnings.filterwarnings('ignore', | ||
r'.+ distutils\b.+ deprecated', | ||
DeprecationWarning) | ||
|
||
|
||
def warn_distutils_present(): | ||
if 'distutils' not in sys.modules: | ||
return | ||
if is_pypy and sys.version_info < (3, 7): | ||
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning | ||
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250 | ||
return | ||
warnings.warn( | ||
"Distutils was imported before Setuptools, but importing Setuptools " | ||
"also replaces the `distutils` module in `sys.modules`. This may lead " | ||
"to undesirable behaviors or errors. To avoid these issues, avoid " | ||
"using distutils directly, ensure that setuptools is installed in the " | ||
"traditional way (e.g. not an editable install), and/or make sure " | ||
"that setuptools is always imported before distutils.") | ||
|
||
|
||
def clear_distutils(): | ||
if 'distutils' not in sys.modules: | ||
return | ||
warnings.warn("Setuptools is replacing distutils.") | ||
mods = [name for name in sys.modules if re.match(r'distutils\b', name)] | ||
for name in mods: | ||
del sys.modules[name] | ||
|
||
|
||
def enabled(): | ||
""" | ||
Allow selection of distutils by environment variable. | ||
""" | ||
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib') | ||
return which == 'local' | ||
|
||
|
||
def ensure_local_distutils(): | ||
clear_distutils() | ||
distutils = importlib.import_module('setuptools._distutils') | ||
distutils.__name__ = 'distutils' | ||
sys.modules['distutils'] = distutils | ||
|
||
# sanity check that submodules load as expected | ||
core = importlib.import_module('distutils.core') | ||
assert '_distutils' in core.__file__, core.__file__ | ||
|
||
|
||
def do_override(): | ||
""" | ||
Ensure that the local copy of distutils is preferred over stdlib. | ||
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401 | ||
for more motivation. | ||
""" | ||
if enabled(): | ||
warn_distutils_present() | ||
ensure_local_distutils() | ||
|
||
|
||
class DistutilsMetaFinder: | ||
def find_spec(self, fullname, path, target=None): | ||
if path is not None: | ||
return | ||
|
||
method_name = 'spec_for_{fullname}'.format(**locals()) | ||
method = getattr(self, method_name, lambda: None) | ||
return method() | ||
|
||
def spec_for_distutils(self): | ||
import importlib.abc | ||
import importlib.util | ||
|
||
class DistutilsLoader(importlib.abc.Loader): | ||
|
||
def create_module(self, spec): | ||
return importlib.import_module('setuptools._distutils') | ||
|
||
def exec_module(self, module): | ||
pass | ||
|
||
return importlib.util.spec_from_loader('distutils', DistutilsLoader()) | ||
|
||
def spec_for_pip(self): | ||
""" | ||
Ensure stdlib distutils when running under pip. | ||
See pypa/pip#8761 for rationale. | ||
""" | ||
if self.pip_imported_during_build(): | ||
return | ||
clear_distutils() | ||
self.spec_for_distutils = lambda: None | ||
|
||
@staticmethod | ||
def pip_imported_during_build(): | ||
""" | ||
Detect if pip is being imported in a build script. Ref #2355. | ||
""" | ||
import traceback | ||
return any( | ||
frame.f_globals['__file__'].endswith('setup.py') | ||
for frame, line in traceback.walk_stack(None) | ||
) | ||
|
||
|
||
DISTUTILS_FINDER = DistutilsMetaFinder() | ||
|
||
|
||
def add_shim(): | ||
sys.meta_path.insert(0, DISTUTILS_FINDER) | ||
|
||
|
||
def remove_shim(): | ||
try: | ||
sys.meta_path.remove(DISTUTILS_FINDER) | ||
except ValueError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__import__('_distutils_hack').do_override() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'stdlib') == 'local'; enabled and __import__('_distutils_hack').add_shim(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008-2021 The pip developers (see AUTHORS.txt file) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Oops, something went wrong.