notes

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit fc7bf0a27e989465d971c0fe1485f8edfc5627bb
parent 73ea1611b91c9cefbb0bcae9abc4809f53c9467b
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Thu, 16 Jan 2025 07:12:02 -0600

Took more notes

Diffstat:
MBasisOfSubspace.md | 16+---------------
ACPP.md | 14++++++++++++++
ADimensions.md | 11+++++++++++
MLinearAlgebra.md | 148+++++++++++++++++++++++++++++++++++++++++++------------------------------------
ALinearMaps.md | 12++++++++++++
ASharedPointers.md | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSpan.md | 4++--
AStandardBasis.md | 9+++++++++
AUniquePointers.md | 40++++++++++++++++++++++++++++++++++++++++
AVector.md | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mindex.md | 1+
11 files changed, 286 insertions(+), 85 deletions(-)

diff --git a/BasisOfSubspace.md b/BasisOfSubspace.md @@ -4,18 +4,4 @@ Khan ## Notes -**Definition:** The basis of a subspace is the span of all linearly independent vectors of a given set of vectors. - -Basically, we have a set of vectors and this is the basis of a subspace whereby the subspace is the span of the vectors (all scalar and additive combinations). - -Note: - -The basis is the **minimum** set of vectors to describe the span of the subspace. As such, all vectors must be linearly independent. - -This can be found two ways. The first is to find RREF of the matrix, write it out as equations, solve for the pivot variables values in relation to the free variables, write this out in vector coeficcient multiplication form, and then the columns we have are our answers. - -Alternatively, we can find the pivot variables using RREF and these columns will contain the basis of the subspace. This is similar to what was done above except is uses the original columns instead of derived columns to state the basis. - -### Intuitive - -The intuitive idea is this is a linearly independent set of vectors. As such, there are infinite basises for a given subspace, but they all have the same cardinality. +**Definition:** The basis of a subspace is list of vectors V := (v_1, v_2, ..., v_m) such that V spans the subspace and is linearly independent. diff --git a/CPP.md b/CPP.md @@ -0,0 +1,14 @@ +# C++ + +This index tracks c++ related concepts. + +## Links + +### Memory Management + +- [UniquePointers](UniquePointers.md) +- [SharedPointers](SharedPointers.md) + +### STL + +- [Vector](Vector.md) diff --git a/Dimensions.md b/Dimensions.md @@ -0,0 +1,11 @@ +# Dimensions + +**Source:** Linear Algebra Done Right + +**Chapter:** 2 + +## Notes + +**Definition:** The dimension of a vector space is defined as the length of any basis of the vector space. + +Recall that the basis of a subspace is by definition linearly independent and thus provides us with the dimension of the vector space. diff --git a/LinearAlgebra.md b/LinearAlgebra.md @@ -9,6 +9,7 @@ The basis of linear algebra is solving systems of equations. Linear Algebra Done Right: Chapter 1: + - [VectorSpace](VectorSpace.md) - [Tuple](Tuple.md) - [ComplexVectorSpace](ComplexVectorSpace.md) @@ -19,83 +20,94 @@ Chapter 1: - [DirectSum](DirectSum.md) Chapter 2: + - [LinearCombination](LinearCombination.md) - [Span](Span.md) - [FiniteDimensional](FiniteDimensional.md) - [LinearIndependence](LinearIndependence.md) +- [BasisOfSubspace](BasisOfSubspace) +- [StandardBasis](StandardBasis.md) +- [Dimensions](Dimensions.md) + +Chapter 3: + +- [LinearMaps](LinearMaps.md) Khan Academy: Khan Unit 1 (mostly): -- [[Matrix.md]] -- [[LinearEquations.md]] -- [[SystemsOfEquations.md]] -- [[LinearCombination.md]] -- [[ColumnSpace.md]] -- [[DistanceCalculation.md]] -- [[DotProduct.md]] -- [[VectorMatrixMultipication.md]] -- [[Invertible.md]] -- [[UnitVector.md]] -- [[Span.md]] -- [[LinearIndependence.md]] -- [[LinearSubspace.md]] -- [[Closure.md]] -- [[BasisOfSubspace.md]] -- [[AngleBetweenVectors.md]] -- [[LawOfCosines.md]] -- [[EquationOfAPlane.md]] -- [[CrossProduct.md]] -- [[Arcsin.md]] -- [[Arccos.md]] -- [[TripleProductExpansion.md]] -- [[NormalVector.md]] -- [[DistanceToPlane.md]] -- [[PlaneToPlaneDistance.md]] -- [[ReducedRowEchelonForm.md]] -- [[Transpose.md]] -- [[NullSpace.md]] -- [[Nullity.md]] -- [[Rank.md]] + +- [Matrix](Matrix.md) +- [LinearEquations](LinearEquations.md) +- [SystemsOfEquations](SystemsOfEquations.md) +- [LinearCombination](LinearCombination.md) +- [ColumnSpace](ColumnSpace.md) +- [DistanceCalculation](DistanceCalculation.md) +- [DotProduct](DotProduct.md) +- [VectorMatrixMultipication](VectorMatrixMultipication.md) +- [Invertible](Invertible.md) +- [UnitVector](UnitVector.md) +- [Span](Span.md) +- [LinearIndependence](LinearIndependence.md) +- [LinearSubspace](LinearSubspace.md) +- [Closure](Closure.md) +- [BasisOfSubspace](BasisOfSubspace.md) +- [AngleBetweenVectors](AngleBetweenVectors.md) +- [LawOfCosines](LawOfCosines.md) +- [EquationOfAPlane](EquationOfAPlane.md) +- [CrossProduct](CrossProduct.md) +- [Arcsin](Arcsin.md) +- [Arccos](Arccos.md) +- [TripleProductExpansion](TripleProductExpansion.md) +- [NormalVector](NormalVector.md) +- [DistanceToPlane](DistanceToPlane.md) +- [PlaneToPlaneDistance](PlaneToPlaneDistance.md) +- [ReducedRowEchelonForm](ReducedRowEchelonForm.md) +- [Transpose](Transpose.md) +- [NullSpace](NullSpace.md) +- [Nullity](Nullity.md) +- [Rank](Rank.md) Khan Unit 2: -- [[Codomain.md]] -- [[Range.md]] -- [[Transformations.md]] -- [[LinearTransformation.md]] -- [[IdentityMatrix.md]] -- [[Image.md]] -- [[Preimage.md]] -- [[Kernel.md]] -- [[DiagonalMatrices.md]] -- [[Rotation.md]] -- [[StandardMatrix.md]] -- [[UnitVector.md]] -- [[Projection.md]] -- [[MatrixMultiplication.md]] -- [[InverseTransformation.md]] -- [[Surjective.md]] -- [[Injective.md]] -- [[Bijective.md]] -- [[Homogeneous.md]] -- [[Inhomogeneous.md]] -- [[Determinant.md]] -- [[RuleOfSarrus.md]] -- [[Hypervolume.md]] -- [[Hyperplane.md]] -- [[AmbientSpace.md]] -- [[Shear.md]] -- [[RightHandRule.md]] -- [[Duality.md]] -- [[CramersRule.md]] -- [[GaussianElimination.md]] -- [[EigenVector.md]] -- [[Transpose.md]] + +- [Codomain](Codomain.md) +- [Range](Range.md) +- [Transformations](Transformations.md) +- [LinearTransformation](LinearTransformation.md) +- [IdentityMatrix](IdentityMatrix.md) +- [Image](Image.md) +- [Preimage](Preimage.md) +- [Kernel](Kernel.md) +- [DiagonalMatrices](DiagonalMatrices.md) +- [Rotation](Rotation.md) +- [StandardMatrix](StandardMatrix.md) +- [UnitVector](UnitVector.md) +- [Projection](Projection.md) +- [MatrixMultiplication](MatrixMultiplication.md) +- [InverseTransformation](InverseTransformation.md) +- [Surjective](Surjective.md) +- [Injective](Injective.md) +- [Bijective](Bijective.md) +- [Homogeneous](Homogeneous.md) +- [Inhomogeneous](Inhomogeneous.md) +- [Determinant](Determinant.md) +- [RuleOfSarrus](RuleOfSarrus.md) +- [Hypervolume](Hypervolume.md) +- [Hyperplane](Hyperplane.md) +- [AmbientSpace](AmbientSpace.md) +- [Shear](Shear.md) +- [RightHandRule](RightHandRule.md) +- [Duality](Duality.md) +- [CramersRule](CramersRule.md) +- [GaussianElimination](GaussianElimination.md) +- [EigenVector](EigenVector.md) +- [Transpose](Transpose.md) Khan Unit 3: -- [[OrthogonalComplement.md]] -- [[Projection.md]] -- [[ChangeOfBasis.md]] -- [[Orthonormal.md]] -- [[GramSchmidtProcess.md]] -- [[EigenVector.md]] + +- [OrthogonalComplement](OrthogonalComplement.md) +- [Projection](Projection.md) +- [ChangeOfBasis](ChangeOfBasis.md) +- [Orthonormal](Orthonormal.md) +- [GramSchmidtProcess](GramSchmidtProcess.md) +- [EigenVector](EigenVector.md) diff --git a/LinearMaps.md b/LinearMaps.md @@ -0,0 +1,12 @@ +# Linear Map + +**Source:** Linear Algebra Done Right + +**Chapter:** 3 + +## Notes + +**Definition:** A linear map is a function f : V -> W where V and W are vector spaces, that has the following properties: + +1. Additivity - T(u + v) = Tu + Tv +2. Homogeneity - T(av) = a(Tv) for all a in F and v in V diff --git a/SharedPointers.md b/SharedPointers.md @@ -0,0 +1,63 @@ +# Shared Pointers + +**Source:** [CPP Reference](https://en.cppreference.com/w/cpp/memory/shared_ptr) + +**Chapter:** N/A + +## Notes + +**Definition:** A shared pointer is a pointer that keeps a reference counter so when the final reference to it goes out of scope, the memory will be freed. + +The value of this is unlike unique_ptr, copies of the pointer can be made. The drawback of this is the overhead both in memory and computation associated with keeping track of the number of pointers that point to the object. + +These should be used when defining your own class to ensure once all pointers to objects of the class type go out of scope, the proper destructor is called. + +An example usage of shared pointers is as follows: + +```cpp + +#include "iostream" +#include "memory" + +class arr{ + public: + int* array = nullptr; + + ~arr(){ + if(array != nullptr){ + delete array; + } + } +}; + + +std::shared_ptr<arr> getSharedPtr(){ + + auto sharedPtr = std::make_shared<arr>(); + int* arr = new int[10]; + sharedPtr->array = arr; + for(int i = 0 ; i < 10; ++i){ + arr[i] = i; + } + return sharedPtr; +} + +int main(){ + std::cout << "Testing Shared Pointer" << std::endl; + while(true){ + std::shared_ptr baseShared = getSharedPtr(); + for(int x = 0 ; x < 100 ; ++x){ + auto shared = baseShared; + for(int i = 0; i < 10; ++i){ + std::cout << shared->array[i] << " "; + } + } + std::cout << std::endl; + } + + return 0; +} + +``` + +In this usage we call a method to create an integer array allocated on the heap. Since make_shared does not support raw arrays, we encapsulated it in a class. We then return this to the main method and show that we can assign pointers to point at the same memory and do manipulations. We then see since it is an infinite loop, it deallocates memory once the last pointer goes out of scope because otherwise the above code would leak memory. diff --git a/Span.md b/Span.md @@ -6,6 +6,6 @@ ## Notes -**Definition:** The span of (v_1, ..., v_m) is the set of all linear combinations of (v_1, ..., v_m). +**Definition:** The span of (v_1, ..., v_m) is the set of all [LinearCombination](LinearCombination.md) of (v_1, ..., v_m). -This may be all R^2, R^3, or some other space. +This may be all R^2, R^3, or some other vector space. diff --git a/StandardBasis.md b/StandardBasis.md @@ -0,0 +1,9 @@ +# Standard Basis + +**Source:** Linear Algebra Done Right + +**Chapter:** 2 + +## Notes + +**Definition:** The standard basis is the [BasisOfSubspace](BasisOfSubspace.md) where each vector is made up of all 0's and one 1. diff --git a/UniquePointers.md b/UniquePointers.md @@ -0,0 +1,40 @@ +# Unique Pointers + +**Source:** [CPP References](https://en.cppreference.com/w/cpp/memory/unique_ptr) + +**Chapter:** N/A + +## Notes + +**Definition:** A unique pointer in c++ is a pointer that can not be copied and once out of scope, automatically deallocates associated memory. + +The value of this is that unlike shared pointers, it does not have any overhead beyond normal pointers. Additionally, once it goes out of scope, the memory is managed automatically. This is useful because we can then return things from a method and not have to worry about deallocation of the memory afterwards. An example of this is shown below: + +```cpp + +#include "memory" +#include "iostream" + +std::unique_ptr<int[]> genPtrToArray(){ + // the <int[]> portion of the left side is optional. + std::unique_ptr<int[]> unique = std::make_unique<int[]>(42); + for(int i = 0; i < 42; ++i){ + unique[i] = i; + } + return unique; +} + +int main(){ + std::cout << "Testing unique pointers."<< std::endl; + + std::unique_ptr<int[]> ptr = genPtrToArray(); + for(int i = 0 ; i < 42; ++i){ + std::cout << ptr[i] << " "; + } + std::cout << std::endl; + return 0; +} + +``` + +In the above code, it is evident that we don't need to call delete despite calling new in the function and by running this code we can verify that the int array allocated in memory does not get deallocated after being returned from the method because we are still able to print out the numbers 0-41 in the main method. diff --git a/Vector.md b/Vector.md @@ -0,0 +1,53 @@ +# Vector (C++) + +## Notes + +**Definition:** Vectors in c++ are dynamically allocated arrays that use the heap instead of the stack. + +Vectors are generally preferred to integer arrays because they can manage their own memory, be resized, and don't have to have a known size at compile time. + +Here is some code that illustrates the properties of them: + +```cpp + +#include "vector" +#include "iostream" + +auto makeVec(){ + std::vector<int> vec = std::vector<int>(); + for(int i = 0 ; i < 1000; ++i){ + vec.push_back(i); + } + return vec; +} + +void sideEffectTest(std::vector<int>* vec){ + for(int i = 0 ; i < 1000; ++i){ + vec->at(i) = 1; + } +} + +int main(){ + + for(int i = 0 ; i < 1000; ++i){ + auto vec = makeVec(); + for(int i = 0 ; i < 1000; ++i){ + //std::cout << vec.at(i) << std::endl; + } + } + + while(true){ + auto vec = makeVec(); + sideEffectTest(&vec); + for(int i = 0 ; i < 1000; ++i){ + std::cout << vec.at(i) << std::endl; + } + } + + return 0; +} + + +``` + +As we can see, vectors can be returned and passed around by value (default) and when this is done side effects don't impact the original vector. If we pass by reference either with a pointer or by specifying the input parameter as std::vector<int>& (this is the preferred way), we can then make changes to the input vector while still having memory managed for us automatically, as shown in the final while(true) loop. diff --git a/index.md b/index.md @@ -26,3 +26,4 @@ This is the index for my main note classifications. I will maintain this as a ho - [Physics](Physics.md) - [ReinforcementLearning](ReinforcementLearning.md) - [DeepLearning](DeepLearning.md) +- [CPP](CPP.md)